Yii创建命令排序

时间:2014-10-09 11:01:53

标签: yii

我希望按ASC或DESC排序,并且我不太确定如何使用Yii执行此操作,我的代码如下所示,但我不知道在哪里订购,因为我需要通过DESC订购时间戳和ASC for homeTeamName。

    $query= Yii::app()->db->createCommand()
                  ->select('*')
                  ->from('livematch')
                  ->where('DATE(timestamp) BETWEEN DATE(NOW()) AND DATE(NOW()) + INTERVAL 7 DAY')
                  ->order(array('timestamp', 'homeTeamName'))
                  ->queryAll();

对此的任何帮助都很棒

2 个答案:

答案 0 :(得分:3)

您可以直接添加它,如下所示:

$query= Yii::app()->db->createCommand()
              ->select('*')
              ->from('livematch')
              ->where('DATE(timestamp) BETWEEN DATE(NOW()) AND DATE(NOW()) + INTERVAL 7 DAY')
              ->order(array('timestamp', 'homeTeamName desc'))
              ->queryAll();

表示:ORDER BY timestamp,homeTeamName DESC

答案 1 :(得分:2)

尝试这样,

$query  = Yii::app()->db->createCommand("SELECT * FROM livematch where DATE(timestamp) BETWEEN DATE(NOW()) AND DATE(NOW()) + INTERVAL 7 DAY order by timestamp desc" );
$std_list = $query->queryAll();