开发者

facebook live search using php jquery mysql, showing 5 results how to show the rest?

开发者 https://www.devze.com 2023-03-15 04:42 出处:网络
hello i\'v built a search, using My开发者_如何学运维SQL, PHP and jQuery, this is the search query using Prepared Statement..

hello i'v built a search, using My开发者_如何学运维SQL, PHP and jQuery, this is the search query using Prepared Statement..

$sql = "SELECT singer_name FROM singers WHERE singer_name LIKE ? LIMIT 5";

now what i want to do is show only 5 results but i want to also show a button with the REST of the results like when you search in facebook the show only 8 of the friends and then a button with "see more resutls for ? showing top 8 results",

how do they do that ? , i'm sure it's fairly simple..


LIMIT has 2 parameters with which you can fetch range of results instead of just first 5.

Check out an article on LIMIT

Example,

$sql = "SELECT singer_name FROM singers WHERE singer_name LIKE ? LIMIT 5, 5";

The above SQL will retrieve results from 5 to 10.

Update:

If you want to show results like "showing first 5 out of 20" then you need to first count the total number of results then apply LIMITs.

$sql = "SELECT COUNT(singer_name) FROM singers WHERE singer_name LIKE ?";

0

精彩评论

暂无评论...
验证码 换一张
取 消