Get particular value in CSqlDataProvider object

Hi guys,

How to get particular value from below array?? i want get the category value in this array… how to get it??

Helpsss…

$dataProvider = $model->getSales();

print_r($dataProvider);

result:


CSqlDataProvider Object ( [db] => [sql] => Array ( [0] => Array ( [category] => Baked Goods [sales] => 26.80 [currency_symbol] => MYR ) [1] => Array ( [category] => Berevages [sales] => 48.90 [currency_symbol] => MYR ) [2] => Array ( [category] => Bread [sales] => 6.00 [currency_symbol] => MYR ) [3] => Array ( [category] => Cake [sales] => 7.10 [currency_symbol] => MYR ) ) [params] => Array ( ) [keyField] => category [_id:private] => [_data:private] => [_keys:private] => [_totalItemCount:private] => 4 [_sort:private] => [_pagination:private] => [_e:private] => [_m:private] => ) 

Hi,

May be using $dataProvider->getData() to get all data of the query, foreach and get category array,

jowen, please use code tag (button with <> on the toolbar) to format your code to be more readable. Thank you…

CSQLDataProvider returns you nothing else then just a simple PHP’s associative array, where all the data is organised exactly as in your database. That is, first level (keys) are all records and second level is a particular record.

So, if you want to get category in your example, all you have to is write something like that:


foreach($dataProvider->getData() as $data)

{

    	print_r($data['category']);

}

(written from memory, not tested, but should work)

BTW: You’re using:


$dataProvider = $model->getSales()

which suggest, that in the return you should get CActiveDataProvider rather than CSQLDataProvider, but I’m not sure…

Hi Trejder,

i will use use code tag (button with <> on the toolbar) next time… =)




$dataProvider = $model->getSales()

. it work perfect…

thanks again.