Re: Nested Arrays

From: Date: Fri, 27 Dec 2002 13:45:16 +0000
Subject: Re: Nested Arrays
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-129427@lists.php.net to get a copy of this message
Sorry, now I reminded myself this would cause a false element at the end of $rows, use this: while($tmp=mysql_fetch_array($res)) { $rows[]=$tmp; } Marek Kilimajer wrote:
Simple: while($rows[]=mysql_fetch_array($res)) {} ($res is a mysql result resource) Beauford.2002 wrote:
Thanks for the info, but maybe I didn't give enough info. I have a mysql database with up to 10 rows and 5 fields in each row.. I have been reading up on some of the array functions, but haven't been able to get anything to work. TIA ----- Original Message ----- From: "Weston Houghton" <ucsu@anapraxis.com> To: "Beauford.2002" <beauford.2002@rogers.com> Cc: "PHP General" <php-general@lists.php.net> Sent: Thursday, December 26, 2002 6:19 PM Subject: Re: [PHP] Nested Arrays
Sure... for the longwinded approach, just do this: $row1 = array("col1", "col2", "col3", ...); $row2 = array("col1", "col2", "col3", ...); $row3 = array("col1", "col2", "col3", ...); $row4 = array("col1", "col2", "col3", ...); $row5 = array("col1", "col2", "col3", ...); $main_array = array($row1, $row2, $row3, $row4, $row5); Obviously these could include key-value pairs in the arrays as well. Then to prove it to yourself: print_r($main_array); Cheers, Wes On Thursday, December 26, 2002, at 06:14 PM, Beauford.2002 wrote:
Hi, Is there anyway to do a nested array, I have looked at the various array functions and can't figure this out (if possible). I want to be able to put each field of a row into an array, and then put that entire row and into another array. so when I display it, I would have: row1 - col1 col2 col3 col4 col5 row2 - col1 col2 col3 col4 col5 row3 - col1 col2 col3 col4 col5 row4 - col1 col2 col3 col4 col5 row5 - col1 col2 col3 col4 col5 etc. (depending on how many rows there are). TIA -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
    


« previous php.general (#129427) next »