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

<?php

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;title).&quot;&amp;cht=bvg&amp;chs=700x350&amp;chbh=a&amp;chd=&quot;. 


  &#036;this-&gt;encodeData(&#036;this-&gt;data).&quot;&amp;chl=&quot;.implode 


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

}

protected function encodeData($data)

{

&#036;chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwx 


  yz0123456789';


&#036;chartData=&quot;s:&quot;;


for(&#036;i=0;&#036;i&lt;count(&#036;data);&#036;i++)


{


  &#036;currentValue=&#036;data[&#036;i];


  if(&#036;currentValue&gt;-1)


    &#036;chartData.=substr(&#036;chars,(&#036;currentValue),1);


  else


    &#036;chartData.='_';


}


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?





$posts=Post::model()->findAll($condition,$params);


$posts=Ur-modelname-for-emp-::model()->findAll();




Hi,

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.

HTH,

Jean-Marie.

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? :)