Yii Framework Forum: Create An Array Of Only Field Values Returned By The Findall() Of Ar Class - Yii Framework Forum

Jump to content

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

Create An Array Of Only Field Values Returned By The Findall() Of Ar Class Rate Topic: -----

#1 User is offline   Sujoy Bhowmick 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 24
  • Joined: 27-December 12

Posted 04 January 2013 - 04:32 AM

Hi,

I need to list out my data retrieved from db table in view as tabular format.I need an array on which i can use foreach and list data row wise in the table.should i use active record's find all method or any other method to do it.if i use findAll() then pls give an example code which help me to understand how to iterate through the result returned by the findAll() and how to create an associative array containing all row of my result set.
0

#2 User is offline   Sujoy Bhowmick 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 24
  • Joined: 27-December 12

Posted 04 January 2013 - 06:13 AM

I find this link very useful Link: http://stackoverflow...-model-to-array
0

#3 User is offline   fouss 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 394
  • Joined: 05-October 10
  • Location:Bamako Mali

Posted 05 January 2013 - 08:23 AM

An easy way...............
//assuming to get tbl_person(name,age)
    public function getPersonArray(){
            $oDbConnection = Yii::app()->db; 
            
            $oCommand = $oDbConnection->createCommand('
            	SELECT name,age from tbl_person
            '
            );
            $oCDbDataReader = $oCommand->queryAll(); 

            foreach ($oCDbDataReader as $result)   {

               $PersonArray[]=array($result['name'],(int)$result['age']);

            }
            return $PersonArray;
    }	

Posted Image
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