Connecting Tech Pros Worldwide Help | Site Map

Array Append

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 17th, 2005, 02:15 PM
Deke
Guest
 
Posts: n/a
Default Array Append

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, 02:15 PM
R. Rajesh Jeba Anbiah
Guest
 
Posts: n/a
Default 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

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.