Problem Inselct Count

this in my function:

public function DailyHitCalculation($HitDate)


        $criteria=new CDbCriteria;

        $criteria->select='count(ID) as CO ,UserID';

        $criteria->condition = 'HitDate=:HitDate and IsValid=:IsValid';

        $criteria->params = array(':HitDate'=>$HitDate,':IsValid'=>1);

        $criteria->group = 'UserID';

        return self::model()->findall($criteria);


but it’s only returning UserID:



    [0] => Hits Object


            [_new:CActiveRecord:private] => 

            [_attributes:CActiveRecord:private] => Array


                    [UserID] => 4


            [_related:CActiveRecord:private] => Array



            [_c:CActiveRecord:private] => 

            [_pk:CActiveRecord:private] => 

            [_alias:CActiveRecord:private] => t

            [_errors:CModel:private] => Array



            [_validators:CModel:private] => 

            [_scenario:CModel:private] => update

            [_e:CComponent:private] => 

            [_m:CComponent:private] => 



The CO is not returning but when i copy paste the generated SQl in phpmyadmin i am getting result which is:

Querying SQL: SELECT count(*) as CO ,UserID FROM `tblhits` `t` WHERE

HitDate=:HitDate and IsValid=:IsValid GROUP BY UserID

Please Advise…

I’m not sure but ‘_attributes’ contains only attributes that exist for this model.

You should add $CO variable to your Model Class.


thanks i don’t know why i forgot to add it