How to show Non database filed in CgridView?

I m using CSqlDataProvider with my own query, the query is like "select user, count(*) as count from table_name.

Now in View I am using CGridView to display this query result.

Since the ‘use’ field is actual table field it is shown correctly by CGridView, but for ‘count’ is is giving exception that Model.count property does not exists.

How can i show non table fields returned by a select query, in CGridView ?

Thanx

you can create a property count in the model by simply:




class MyModel extends CActiveRecord

{


   public $count



And then make sure that the retrive count is named exactly like the property:




select user, count(*) as count, ...



The way you expose your question is very confused:

SELECT name, count(*) as count FROM tblname (GROUP BY name -I guess)

This will give you the count of the whole table per row.

Consider reviewing your code and for statistical data use a relation (self::STAT) instead and then you can call :

modelname->relationnameCount in your CGridView

Soryy i forgot to write group by

This is my exact query

[i]select a1.user, tot, prov,pend from

(select user, count() tot from mobile group by user order by count() desc) as a1 left join

(select user, count(*) prov from mobile where cug_status=‘Provisioned’ group by user ) as a2 on a1.user=a2.user

left join

(select user, count(*) pend from mobile where cug_status=‘Pending’ group by user ) as a3 on a1.user=a3.user

[/i]

You have just to create the properties for tot, prov and pend, all will work fine

There you go… good zac

Still, I would prefer going by having some statistical relations on user.

Thanx zaccaria, it worked :)

Thanks Guys ! This helped me as well.