Connecting Tech Pros Worldwide Help | Site Map

Array Append

  #1  
Old July 17th, 2005, 03:15 PM
Deke
Guest
 
Posts: n/a
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')
)
  #2  
Old July 17th, 2005, 03:15 PM
R. Rajesh Jeba Anbiah
Guest
 
Posts: n/a

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
server side javascript array jvcoach23 answers 5 February 28th, 2008 04:45 PM
Converting a bidimensional list in a bidimensional array Santiago Romero answers 8 January 11th, 2008 06:45 PM
List append mouseit answers 4 September 16th, 2007 04:35 AM
Pass ASP Array variable to Javascript Augusto Cesar answers 2 November 17th, 2005 11:16 PM