开发者

How to select particular rows on a MySQL table?

I have a table called 'topics' in which all topics are saved. I want to select the latest 5 rows from that table, show them on one page, then select THE OTHER FIVE latest ones and show them on the other page.

I know how to echo all the topic names in a while loop, but the problem here is making mysql select 5 rows, then the other five for another page, not the same ones again. How to a开发者_StackOverflowchieve this?


SELECT
*
FROM tablename
ORDER BY id DESC
LIMIT 0, 5

on the another page:

LIMIT 5, 5


$start = 0;
$count= 5;
$query = "select *
    from topics
    order by date desc
    limit $start, $count"


First 5:

SELECT * FROM your_table ORDER BY any_order_criteria LIMIT 0,5

Second 5:

SELECT * FROM your_table ORDER BY any_order_criteria LIMIT 5,5


What i got from your problem is that you want to enable Pagination on your page.

This is a wonderful article on Pagination using PHP and MySQL.

http://www.tonymarston.net/php-mysql/pagination.html

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜