php Yii findAllByAttributes with BETWEEN DATES and ORDER BY
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/14965013/
Warning: these are provided under cc-by-sa 4.0 license.  You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 08:17:01  来源:igfitidea点击:
Yii findAllByAttributes with BETWEEN DATES and ORDER BY
提问by chulian
Im tring to do a search by attributes, on a given date range and ordered by date created, but no luck.
我想在给定的日期范围内按属性进行搜索,并按创建日期排序,但没有运气。
$user = array('user_country'=>1 ,'user_gender'='M');
    $rows = User::model()->findAllByAttributes($user,array("user_date_created BETWEEN '2012' AND '2013' " ,'order'=> 'user_date_created') );
Thank you in advance.
先感谢您。
回答by chulian
Had to use a CDbCriteria, like this:
必须使用CDbCriteria,如下所示:
$attribs = array('user_country'=>1 ,'user_gender'=>'M');
$criteria = new CDbCriteria(array('order'=>'user_date_created DESC','limit'=>10));
$criteria->addBetweenCondition('user_date_created', $date['date_start'], $date['date_end']);
$rows = user::model()->findAllByAttributes($attribs, $criteria);
Hope it helps somebody in the future
希望它在未来对某人有所帮助
回答by Victor Azevedo
You can use to:
您可以用来:
$criteria = new CDbCriteria;
$criteria->condition = "date_start >= '$date_start' AND date_end <= '$date_end'";
$model = TemporadaAlta::model()->find($criteria);

