getting data from data base table to an array?

can any one help in getting data from a database table into an array

this is my widget php file in protected/chart/EchartWidget.php

and the code is as below


class EChartWidget extends CWidget


public $title;

public $data=array();

public $labels=array();

public function run()


echo &quot;&lt;img  

  src=&#092;&quot;here is url=&quot;.urlencode 



  ('|', &#036;this-&gt;labels).&quot;&#092;&quot;&gt;&quot;;


protected function encodeData($data)













return &#036;chartData.&quot;&amp;chxr=0,0,350,25&amp;chxt=y&amp;chxl=0:|0|&quot;;



and i have supplied data to it in view index.php file like this

$this->widget(‘ext.chart.EChartWidget’, array(

  'title' =&gt; 'Employees Details',

  'data' =&gt; array(61,36,18),

  'labels' =&gt; array(

    'total Employees',

    'male Employees',

    'female Employees'



i want to get the data and labels from a database table tbl_emp is there anyway we can do that?




You did not tell us much about your DB.

If you are using ActiveRecords, maybe CActiveRecord::count and CActiveRecord::countByAttributes will help.

Else, you could use the QueryBuilder.



thanks for your reply can you explain me with a simple example

my database is

detail number

total employees 300

male employees 200

female employees 100

i want to get that number column in to an array

There are a number of different solutions there. Which of these do you feel is best? :)