I need help with adding condition to php live search
I am just learning php and ended开发者_JAVA技巧 up at this tutorial http://www.w3schools.com/php/php_ajax_livesearch.asp
Till now my PHP search file looks the same as in example but i changed the if (strlen($q) > 0)
to if (strlen($q) > 3)
to display results after typing minimum 3 words. I am wondering how can i make the results paginate if there are lots of them?
Thanks
Roshan
You would need to page after obtaining the number of records from your database. Paging should be done by the same script that echos your ajax response.
Here is how to page: PHP MySQL paging.
The idea of search suggestions is to show the user what do you have in your site, in terms of relevance, that match his query. This being said, you should only throw a subset of results, being the first result the most relevant, instead of the whole file or database. In others words, you don't need pagination.
Show the user 5 or 10 items, if he doesn't find what he's after he'll keep writing until he finds it. If he doesn't finds it he will just search it. Remember that it is a suggestion and nothing more.
精彩评论