Stacking rows from a database in an array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lynchpin
Forum Commoner
Posts: 60
Joined: Mon Jul 21, 2008 1:31 pm

Stacking rows from a database in an array

Post by lynchpin »

Hi,
I want to be able to stack rows returned from a database query in an array which I can then pass to another file for display.
Here's a sample code of how am trying to achieve this, but it's obviously not working.
by the way am using PDO objects to retrieve the rows.
------------------------------------------------
while($row = $this->obj_db_cnx->safe_fetch_array()) {

$this->ary_result['users'] = $row;

}

------------------------------------------------------

But the when I pass the ary_result['users'] as a parameter to another file, only the last row is displayed.

Please advice.

Thanks.
User avatar
panic!
Forum Regular
Posts: 516
Joined: Mon Jul 31, 2006 7:59 am
Location: Brighton, UK

Re: Stacking rows from a database in an array

Post by panic! »

try

Code: Select all

 
while($row = $this->obj_db_cnx->safe_fetch_array()) {
 
$this->ary_result['users'][] = $row;
 
}
 
lynchpin
Forum Commoner
Posts: 60
Joined: Mon Jul 21, 2008 1:31 pm

Re: Stacking rows from a database in an array

Post by lynchpin »

Thanks a lot Panic!

it works like a charm :lol:
User avatar
panic!
Forum Regular
Posts: 516
Joined: Mon Jul 31, 2006 7:59 am
Location: Brighton, UK

Re: Stacking rows from a database in an array

Post by panic! »

No probs at all!

:)
Post Reply