dongyi6195 2019-04-27 08:30
浏览 67

当我连接表时,分页和数据提供者的问题

I want to select some record from 4 table, 1 main table : "user" and 3 other tables.(name of models is : t1,t2,t3) and there are one to many relation between "user" and 3 other table, I want to select all records from table user that Which is in one of the three tables, If there are no information in 3 tables in each of these, then the record will not be selected from table user.

I use from CDbCriteria, I think condition in $criteria is correct , Choose the correct data. Because there is no problem if I do not use pagination and all the records are displayed one at a time in view page. (CGridView widget)

but in pagination I have problem. afterward my bets runs pagination. for example: If pageSize of pagination is 20. select 20 records from the user table, and 13 of these 20 numbers are linked to the other tables. The first page of the view page only shows 13 users.should contain 20 records in view page. And so each page displays a number of different records. It selects from 20 records and eliminates the records that do not contain the condition. What remains is displayed, this will cause the number of rows to be irregular.

$criteria = new CDbCriteria();
            $criteria = array(
               'with' => array(
                    't1' => array(
                       'together' => true,
                        'joinType' => 'LEFT  JOIN',

                    ),
                    't2' => array(
                       'together' => true,
                        'joinType' => 'LEFT JOIN',

                   ),
                     't3' => array(
                       'together' => true,
                        'joinType' => 'LEFT JOIN',

                  ),
                ),
                 'condition' => '(t1.user_Id=user.id or t2.user_Id=user.id or t3.user_Id=user.id ) ',

            );


            $dataProvider = new CActiveDataProvider('User',  array(

                 'pagination' => array(
                    'pageSize' => '20',
                ),
                 'criteria' => $criteria,
                'sort' => array(
                   'defaultOrder' => 'username DESC',
                ),   
                    ));

Displaying only 13 records instead of 20

Displaying only 10 records instead of 20

Displaying only 4 records instead of 20

Displaying only 3 records instead of 20!!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
    • ¥15 ETLCloud 处理json多层级问题
    • ¥15 matlab中使用gurobi时报错
    • ¥15 这个主板怎么能扩出一两个sata口
    • ¥15 不是,这到底错哪儿了😭
    • ¥15 2020长安杯与连接网探
    • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
    • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
    • ¥15 可见光定位matlab仿真
    • ¥15 arduino 四自由度机械臂