隨筆 - 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 閱讀(3470) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 那坡县| 开化县| 铜川市| 冷水江市| 莲花县| 北流市| 璧山县| 闸北区| 南川市| 仙桃市| 拉孜县| 航空| 北安市| 宁德市| 江陵县| 会昌县| 蚌埠市| 苏尼特左旗| 阿鲁科尔沁旗| 云浮市| 彝良县| 金乡县| 长汀县| 和平区| 阳朔县| 鄄城县| 时尚| 河源市| 高阳县| 琼结县| 安图县| 广州市| 札达县| 定襄县| 威海市| 周口市| 大新县| 新竹市| 呼伦贝尔市| 白玉县| 武山县|