Display SQL result

Hi there!

I would like to display result of SQL query in something like CGridview. But Cgridview accept only a list of item and I can only have a list of array with CSqlDataProvider. Is there an other widget which display data after SQL query?



it should be possible to pass any C*DataProvider to the gridview. It doesn’t matter if it is a CSqlDataProvider or a CActiveDataProvider.


Here is my code:

$count=Yii::app()->db->createCommand('SELECT COUNT(*) contract')->queryScalar();

$sql='SELECT * FROM contract';

$dataProvider=new CSqlDataProvider($sql, array(




             'f_contract_id','f_site_id', 'f_expiry_date', 'f_price_unit',







// $dataProvider->getData() will return a list of arrays.

$this->widget('zii.widgets.grid.CGridView', array(








Like this I get the following error:

Without getData() I get this error:

Have you an idea?

See this thread.


Thanks! It’s exactly what I need!

You could also use CArrayDataProvider instead of SqlDataProvider if you hasn’t linked your query to a particular model :

Check this thread

Many thanks This was just what I was looking for!!!!