开发者

php and MySql paging through long lists of data

开发者 https://www.devze.com 2023-02-04 11:44 出处:网络
I\'m letting the user page through lists of data. I implemented it with 2 sql statements one to get the count and one to let them get the next section. I 开发者_开发百科get the count to show the numbe

I'm letting the user page through lists of data. I implemented it with 2 sql statements one to get the count and one to let them get the next section. I 开发者_开发百科get the count to show the number of pages and let the user click on any page, such as:

<< < 1 2 3 4 5 > >> 245 Items

SELECT count(*) FROM list;

SELECT * FROM list limit "$start $rows";

I was just wondering if there was a better way. It looks inefficient, particularly since my SQL is complicated with lots of joins and conditions that I have to execute twice.

Thanks


SELECT SQL_CALC_FOUND_ROWS name, email FROM users WHERE name LIKE 'a%' LIMIT 10;

SELECT FOUND_ROWS();

Source: http://www.arraystudio.com/as-workshop/mysql-get-total-number-of-rows-when-using-limit.html

0

精彩评论

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