limit连贯查询怎么分页麻烦了 [ 2.0 版本 ]
$count=10
$page=2
$pagination = new \yii\data\Pagination([
'totalCount' => $count,
'defaultPageSize' => $page,
]);
$list=$this->sql->from($this->aaa)
->where('a=1')
->limit($pagination->limit)
->select('id')
->all();
SELECT * from AAA
where a=1 LIMIT 10` 结果始终是这样的
我要的是 LIMIT 2,10
蛋蛋的蛋 补充于 2018-05-15 13:20
$pagination = new \yii\data\Pagination([
'totalCount' => $count,
'defaultPageSize' => $page,
]);
$list=$this->sql->from($this->aaa)
->where('a=1')
->offset($pagination->offset)
->limit($pagination->limit)
->select('id')
->all();
我又加了 ->offset($pagination->offset)
进去了。还是limit 10
蛋蛋的蛋 补充于 2018-05-16 11:42
自己解决了.
new Expression
->orderBy(new Expression($orddr.' limit '.($tiaoshu * ($zoshu - 1)).','.$tiaoshu.';'))
或者
->offset($tiaoshu * ($zoshu - 1))
->limit($tiaoshu)
共 4 个回答
-
// $pagination = new Pagination(['defaultPageSize' => 10]); $pagination = new Pagination(['defaultPageSize' => 2]); $unit = Unit::find()->limit($pagination->limit); echo $unit->createCommand()->getRawSql();die;
SELECT * FROM
mall_unitLIMIT 2
测试过了 limit 是2 你再确认下 你的代码你打印下
$pagination
yii\data\Pagination Object ( [pageParam] => page [pageSizeParam] => per-page [forcePageParam] => 1 [route] => [params] => [urlManager] => [validatePage] => 1 [totalCount] => 0 [defaultPageSize] => 2 [pageSizeLimit] => Array ( [0] => 1 [1] => 50 ) [_pageSize:yii\data\Pagination:private] => [_page:yii\data\Pagination:private] => )
共 1 条回复
蛋蛋的蛋
注册时间:2018-04-02
最后登录:2024-03-11
在线时长:34小时29分
最后登录:2024-03-11
在线时长:34小时29分
- 粉丝4
- 金钱64
- 威望20
- 积分604