以10个为一组读取Mysql数据库

时间:2012-04-04 20:25:22

标签: php mysql

我需要能够一次读取Mysql数据库10条记录的内容,以便我可以显示前10条,然后当用户点击第2页时,我需要能够读取第二块10个记录,前10个等等

这是我用来阅读前10个

的内容
$result = mysql_query("SELECT id FROM general_thread WHERE id_topic = $id");
$num_rows = mysql_num_rows($result);


$result = mysql_query("SELECT id, user_message, user_created, user_id, user_posts, user_rank, date_created FROM general_thread WHERE id_topic = $id ORDER BY id DESC
LIMIT 10;") 
or die(mysql_error()); 

1 个答案:

答案 0 :(得分:1)

不仅仅是

$result = mysql_query("SELECT id, user_message, user_created, user_id, user_posts, user_rank, date_created FROM general_thread WHERE id_topic = $id ORDER BY id DESC LIMIT 10, 10;")

接下来的10?然后

$result = mysql_query("SELECT id, user_message, user_created, user_id, user_posts, user_rank, date_created FROM general_thread WHERE id_topic = $id ORDER BY id DESC LIMIT 20, 10;")

之后的10?

http://php.about.com/od/mysqlcommands/g/Limit_sql.htm