Page 1 of 1

Stacking rows from a database in an array

Posted: Tue Sep 09, 2008 5:51 am
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.

Re: Stacking rows from a database in an array

Posted: Tue Sep 09, 2008 6:19 am
by panic!
try

Code: Select all

 
while($row = $this->obj_db_cnx->safe_fetch_array()) {
 
$this->ary_result['users'][] = $row;
 
}
 

Re: Stacking rows from a database in an array

Posted: Tue Sep 09, 2008 7:20 am
by lynchpin
Thanks a lot Panic!

it works like a charm :lol:

Re: Stacking rows from a database in an array

Posted: Tue Sep 09, 2008 7:40 am
by panic!
No probs at all!

:)