Yii:: Select Distinct Year From Date

Posted: October 7, 2010 in Yii Framework

Yii:: Select Distinct Year From Date as year1

First, declare the variable for ‘AS’ in your model.

eg: public $year1;

Second, in your file:

$criteria=new CDbCriteria;
$criteria->select=’YEAR(t.date_time) as year1′; //declare year1 in model
$criteria->distinct=true;

$rs = TblTransaction::model()->findAll($criteria);

OR output to dropdown

echo CHtml::dropDownList(‘year’, $year, CHtml::listData($rs, ‘year1’, ‘year1’), array(‘prompt’=>'[Select Year]’, ‘onchange’=>’form.submit()’));

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s