1

我想如何UNION ALL使用CActiveDataProvider criteria.

表示例:

ID    NAME
1     John

查询示例:

SELECT * FROM users 
  UNION ALL 
SELECT * FROM users

回复:

ID    NAME
1     John
1     John
4

1 回答 1

3

CDbCriteria似乎不处理UNION ALL

相反,您可以使用CSqlDataProvider该类

$sql='SELECT * FROM tbl_user UNION ALL SELECT * FROM tbl_user ';
$dataProvider=new CSqlDataProvider($sql, array(
    'totalItemCount'=>$count,
    'sort'=>array(
        'attributes'=>array(
             'id', 'username', 'email',
        ),
    ),
    'pagination'=>array(
        'pageSize'=>10,
    ),
));
// $dataProvider->getData() will return a list of arrays.
于 2013-01-17T08:08:15.440 回答