Re: Array Append
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.php archive

Re: Array Append

From: R. Rajesh Jeba Anbiah <ng4rrjanbiah@rediffmail.com>
Date: Sun Jul 17 2005 - 11:04:19 CEST

Deke wrote:
> How may I programatically append and create the following predefined
> array in PHP?
>
> Although the example has all the data and the subsequent arraw
> predifined I must create an array while iterating through the rows in an
> RDBMS.
>
> Thanks
>
> array(
> array('name' => 'bob', 'phone' => '555-3425'),
> array('name' => 'jim', 'phone' => '555-4364'),
> array('name' => 'joe', 'phone' => '555-3422'),
> array('name' => 'jerry', 'phone' => '555-4973'),
> array('name' => 'fred', 'phone' => '555-3235')
> )

table_foo: id, name, phone

$tbl_data_arr = array();
$db->dbQuery('SELECT id, name, phone FROM table_foo');
while($row=$db->dbFetchRow())
   $tbl_data_arr[] = $row; //this is the logic you wanted.
print_r($tbl_data_arr);

Note: I used some DB wrappers (don't get confused). But, never use
similar in developement or production version. Dumping the records from
DB into array is serious performance issue. Do the processing in DB
layer (query itself) and output the records one by one; don't dump them
into array.

--
  <?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com    Blog: http://rajeshanbiah.blogspot.com
Received on Mon Oct 17 21:09:09 2005