can any one help in getting data from a database table into an array
Page 1 of 1
getting data from data base table to an array?
#2
Posted 02 May 2012 - 12:12 AM
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?
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?
#3
Posted 02 May 2012 - 01:26 AM
$posts=Post::model()->findAll($condition,$params); $posts=Ur-modelname-for-emp-::model()->findAll();
Rajith Ramachandran,
Wiwo inc.
| Mobile: 919995504508
Wiwo inc.
| Mobile: 919995504508
#4
Posted 03 May 2012 - 01:03 AM
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.
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.
#5
Posted 07 May 2012 - 06:57 PM
Rajith R, on 02 May 2012 - 01:26 AM, said:
$posts=Post::model()->findAll($condition,$params); $posts=Ur-modelname-for-emp-::model()->findAll();
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
#7
Posted 31 December 2012 - 12:50 PM
Share this topic:
Page 1 of 1

Help

















