各位大家好我想问你为什么,当我把限制0,5和5,10时,它无法正常运行,这是我的代码。
$sql = mysql_query("SELECT * FROM vn_questions WHERE published = 1 limit 0,5 ");
while($data=mysql_fetch_array($sql))
{
echo $data['author'];
}
它给了我5个结果,但是当我把
$sql = mysql_query("SELECT * FROM vn_questions WHERE published = 1 limit 5,10 ");
while($data=mysql_fetch_array($sql))
{
echo $data['author'];
}
它给了我6 ..问题在哪里以及如何解决?我尝试+1 -1但输出无法正常工作。
答案 0 :(得分:2)
MYSQL LIMIT
的语法是LIMIT OFFSET COUNT
,所以你的第二个查询说的是从记录5开始,并显示10个结果。你的桌子里只有6条记录吗?因为它不到10,所以只能显示那6个。
从SQL手册
With two arguments, the first argument specifies the offset of the first row to return, and the second specifies the maximum number of rows to return. The offset of the initial row is 0 (not 1):
和
With one argument, the value specifies the number of rows to return from the beginning of the result set: