• 欢迎光临~

分页查询中order排序失效原因

开发技术 开发技术 2022-10-24 次浏览
$this->db->order("position desc")->paginate(2);

一个排序功能,根据某字段的大小值排序,发现order失效;

原因如下:

object(thinkpaginatordriverBootstrap)#20 (9) {
  ["simple":protected] => bool(false)
  ["items":protected] => object(thinkCollection)#19 (1) {
    ["items":protected] => array(2) {
      [0] => array(8) {
        ["id"] => int(7)
        ["classify"] => string(6) "测试1"
        ["quantity"] => string(1) "0"
        ["state"] => string(1) "1"
        ["uptime"] => string(10) "1663983778"
        ["time"] => string(10) "1663983778"
        ["operator"] => string(5) "admin"
        ["position"] => string(2) "12"
      }
      [1] => array(8) {
        ["id"] => int(1)
        ["classify"] => string(6) "测试2"
        ["quantity"] => string(1) "0"
        ["state"] => string(1) "1"
        ["uptime"] => string(10) "1663899645"
        ["time"] => string(10) "1663899645"
        ["operator"] => string(5) "admin"
        ["position"] => string(4) "1000"
      }
    }
  }
} 

//根据['position']排序的  输出显示order并未生效  字段类型为 string
//把['position']字段的数据类型修改为 int 排序生效
程序员灯塔
转载请注明原文链接:分页查询中order排序失效原因
喜欢 (0)