Connecting Tech Pros Worldwide Forums | Help | Site Map

Array Append

Deke
Guest
 
Posts: n/a
#1: Jul 17 '05
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')
)
R. Rajesh Jeba Anbiah
Guest
 
Posts: n/a
#2: Jul 17 '05

re: Array Append


Deke wrote:[color=blue]
> 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')
> )[/color]

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

Closed Thread