随笔 - 25  文章 - 32  trackbacks - 0
<2008年7月>
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789

常用链接

留言簿(2)

随笔档案

文章分类

文章档案

相册

搜索

  •  

最新评论

阅读排行榜

评论排行榜


用mysql的limit进行分页。。发现竟然有些数据没显示在页面上。。总共才24条数据。楞找不到。。
后来把语句弄到mysql上查了一下才知道。这条语句中的limit有问题。。有些数据在第二页被重复显示了。。
非常郁闷。。下面给截图
查第一页的语句

SQL code
            
SELECT * FROM article a where a.type in (1,2,4) limit 0,20;

第一页的结果
(注意红色部分)
第二页的语句

SQL code
            
SELECT * FROM article a where a.type in (1,2,4) limit 20,20;

结果:
(注意红色部分)
--------------------------------------------------------------------------
后来发现排下序就没事了。。原来用MySQL的limit必须排序。。唉
这是一位网友给的MySQL Help:
If you use LIMIT row_count with ORDER BY, MySQL ends the sorting as soon as it has found the first row_count rows of the sorted result, rather than sorting the entire result. If ordering is done by using an index, this is very fast. If a filesort must be done, all rows that match the query without the LIMIT clause must be selected, and most or all of them must be sorted, before it can be ascertained that the first row_count rows have been found. In either case, after the initial rows have been found, there is no need to sort any remainder of the result set, and MySQL does not do so.
..用limit必须排序,,切记切记...
posted on 2008-07-18 17:54 phyeas 阅读(3456) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: