yii如何在queryall中选择日期范围
这是我的问题yii如何在queryall中选择日期范围,yii,Yii,这是我的问题 $query= Yii::app()->db->createCommand() ->select('*,SUM(amount) AS TotalItemsOrdered') ->from('shoppinglist') ->where('user_type="Admin" ') ->gro
$query= Yii::app()->db->createCommand()
->select('*,SUM(amount) AS TotalItemsOrdered')
->from('shoppinglist')
->where('user_type="Admin" ')
->group('cat_id,ing_id,measure_id')
->queryAll();
我从今天开始,在当前日期中加上6天,以获得最后一个日期(假设为完整的一周)
$startdate=“7-3-14”//月日年
$enddate=“7-7-14”;
如何在日期(“$DateFrom\u order”)和日期(“$DateTo\u order”)之间使用此代码Date
或者我在mysql的语句中使用,但如何在上面的YII查询中使用或余烬
编辑
这是我的模型
<?php
}如果数据库中的字段日期为日期(类型),则:
感谢@psk$recipeIngs=Yii::app()->db->createCommand()->选择('*,SUM(amount)AS TotalItemsOrdered')->来自('shoppinglist')->其中('user_type='Admin'和('currentDate'和'$ending_date'之间添加的日期)->组('cat_id,ing_id,measure_id'))->queryAll();你们为什么这么用yii。。。在我看来像SQL;)发布你的模型,我会分三行完成。干杯。我已经用模型更新了我的问题。请用三行告诉我你是如何做到这一点的:)请发布你的购物清单模型。您的解决方案并不酷,我们应该使用模型来捕获您的数据
public static function model($className=__CLASS__)
{
return parent::model($className);
}
public function tableName()
{
return 'shoppinglist';
}
/**
* @return array validation rules for model attributes.
*/
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('ing_id, measure_id, amount, user_id, cat_id, date_added, user_type', 'required'),
array('ing_id, measure_id, amount, user_id, cat_id', 'numerical', 'integerOnly'=>true),
array('user_type', 'length', 'max'=>5),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('id, ing_id, measure_id, amount, user_id, cat_id, date_added, user_type', 'safe', 'on'=>'search'),
);
}
/**
* @return array relational rules.
*/
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
);
}
/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'id' => 'ID',
'ing_id' => 'Ing',
'measure_id' => 'Measure',
'amount' => 'Amount',
'user_id' => 'User',
'cat_id' => 'Cat',
'date_added' => 'Date Added',
'user_type' => 'User Type',
);
}
/**
* Retrieves a list of models based on the current search/filter conditions.
* @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
*/
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->compare('id',$this->id);
$criteria->compare('ing_id',$this->ing_id);
$criteria->compare('measure_id',$this->measure_id);
$criteria->compare('amount',$this->amount);
$criteria->compare('user_id',$this->user_id);
$criteria->compare('cat_id',$this->cat_id);
$criteria->compare('date_added',$this->date_added,true);
$criteria->compare('user_type',$this->user_type,true);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
$query= Yii::app()->db->createCommand()
->select('*,SUM(amount) AS TotalItemsOrdered')
->from('shoppinglist')
->where("user_type='Admin' AND Date BETWEEN STR_TO_DATE( '$startdate', '%d-%m-%y' ) AND STR_TO_DATE( '$enddate', '%d-%m-%y' )")
->group('cat_id,ing_id,measure_id')
->queryAll();