Hello i have a Ionic Angular project with PHP as backend. I created a search for users but in order for the project to run more faster i put a LIMIT of 20 users in the php function that calls the users and call the next 20 with an Angular PIPE function and so on.

So the user has to scroll down in order for the next 20 users to show and be able to search those names. Otherwise the search results work only for the first 20 names.

That way i can't put any filters also. Any way that a user may do a search in all the users in the database table?

PHP function

$sql = "SELECT f.friend_id,f.friend_two,f.friend_one, U.uid,U.username,U.name,U.first_name,U.last_name, U.profile_pic,U.media_edits,U.updates_count,U.friend_count,U.profile_views,U.group_count,U.bio,U.location,U.artisticBehaviour
 FROM users U ";
 $sql .= $sql_friends;
 $sql .=" LIMIT $offset, $limit";

Angular PIPE

 import {Pipe, PipeTransform} from '@angular/core';

@Pipe({
name: 'search',
})
export class SearchPipe implements PipeTransform {
 /**
* Takes a value and makes it lowercase.
*/
 transform(items: any[], terms: string): any[] {
if (!items) return [];
if (!terms) return items;

terms = terms.toLowerCase();
return items.filter(it => {

    if (it.group_name) {
        return it.group_name.toLowerCase().includes(terms);    
    }
    else if (it.username || it.title)
    {
        var match_username = it.username ? it.username.toLowerCase().includes(terms) : false;
        var match_title = it.title ? it.title.toLowerCase().includes(terms) : false;
        return match_username || match_title;
    }
    else 'No results';
});
}
}

It's been a couple years since my last MySQL work but I don't recall there was any restriction to using filters along with OFFSET and LIMIT.

That is, your SQL query returns a set which you can filter as you see and then the OFFSET and LIMIT is applied to get to your final set or collection. So apply your filters and test that you get the search you desire.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.