Yii Framework Forum: getting data from data base table to an array? - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

getting data from data base table to an array? Rate Topic: ***** 1 Votes

#1 User is offline   manapragada 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 01-May 12

Posted 02 May 2012 - 12:05 AM

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

#2 User is offline   manapragada 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 01-May 12

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?
0

#3 User is offline   Rajith R 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 876
  • Joined: 20-April 11
  • Location:India

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
0

#4 User is offline   Jean-Marie 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 14
  • Joined: 12-April 12
  • Location:Brittany, France.

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.
0

#5 User is offline   manapragada 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 01-May 12

Posted 07 May 2012 - 06:57 PM

View PostRajith 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
0

#6 User is offline   yasen 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 32
  • Joined: 29-October 11
  • Location:Sofia, Bulgaria

Posted 31 December 2012 - 06:59 AM

http://stackoverflow...-model-to-array
0

#7 User is offline   Backslider 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 363
  • Joined: 23-July 09

Posted 31 December 2012 - 12:50 PM

View Postyasen, on 31 December 2012 - 06:59 AM, said:



There are a number of different solutions there. Which of these do you feel is best? :)
We were all once expert at....... nothing.

yii-language-behavior

My Blog
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users