原来错误写法:
$list=Db::name('log')->field('id,title,content,username,time,controller')->where($where)->order($od)->limit($limit)->page($page)->select();
$list2=Db::name('log')->field('id')->where($where)->select();
$count=count($list2);//取得记录集总条数
$list2=Db::name('log')->field('id')->where($where)-->select()
这种用法,就是再重新查一次,太费资源了
正确写法:
用count()统计数量,官方教程:https://www.kancloud.cn/manual/thinkphp5_1/354028
$count=Db::name('log')->where($where)->count();//取得记录集总条数
$list=Db::name('log')->field('id,title,content,username,time,controller')->where($where)->order($od)->limit($limit)->page($page)->select();
$count=Db::name('log')->where($where)->count();//取得记录集总条数