can any one help in getting data from a database table into 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 "<img
src=\"here is url=".urlencode
($this->title)."&cht=bvg&chs=700x350&chbh=a&chd=".
$this->encodeData($this->data)."&chl=".implode
('|', $this->labels)."\">";
}
protected function encodeData($data)
{
$chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwx
yz0123456789';
$chartData="s:";
for($i=0;$i<count($data);$i++)
{
$currentValue=$data[$i];
if($currentValue>-1)
$chartData.=substr($chars,($currentValue),1);
else
$chartData.='_';
}
return $chartData."&chxr=0,0,350,25&chxt=y&chxl=0:|0|";
}
}
and i have supplied data to it in view index.php file like this
$this->widget(‘ext.chart.EChartWidget’, array(
'title' => 'Employees Details',
'data' => array(61,36,18),
'labels' => 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?