Iterate through Multi-Dimensional Arrays

From: Date: Fri, 11 Jan 2002 20:23:01 +0000
Subject: Iterate through Multi-Dimensional Arrays
Groups: php.db 
Request: Send a blank email to php-db+get-15671@lists.php.net to get a copy of this message
Hi all, I have a multidimesional array that holds consultants and their details. I've tried this a number of ways but to no avail. Could someone help me out iterating through the first and then the second array and display those results on my webpage. I messed it up pretty badly :( heh Here's my code : Thx Joe :) // fetch the data from the database while(odbc_fetch_row($resultset)){ $consultantdetailsarray[0] = odbc_result($resultset, 1); $consultantdetailsarray[1] = odbc_result($resultset, 2); $consultantdetailsarray[2] = odbc_result($resultset, 3); $consultantdetailsarray[3] = odbc_result($resultset, 4); $consultantdetailsarray[4] = odbc_result($resultset, 5); $consultantdetailsarray[5] = odbc_result($resultset, 6); $consultantdetailsarray[6] = odbc_result($resultset, 7); $consultantdetailsarray[7] = odbc_result($resultset, 8); file://dump each consultant into the new array called $consultantarray $consultantarray[$x] = $consultantdetailsarray; $x++; } file://loop through the elements of retrieved array (2nd one holding the consultant details) for($y = 0; $y < count($consultantarray); +){ for($z = 0; $z < count($consultantdetailsarray[$y][$x]); $z++){ list($consultantid, $firstname, $lastname, $city, $stateprovince, $country, $category, $yearsexp) = $consultantdetailsarray; print "<tr><td align=left><font color='#663399' face='verdana' size=2><a href='consultantdetails.php?cid=" . $cid . "'>" . $firstname . " " . $lastname . "</a></font></td><td align=left><font color='#663399' face='verdana' size=2>" . $city . "</font></td><td align=left><font color='#663399' face='verdana' size=2>" . $stateprovince . "</font></td><td align=left><font color='#663399' face='verdana' size=2>" . $country . "</font></td><td align=left><font color='#663399' face='verdana' size=2>" . $category . "</font></td><td align=left><font color='#663399' face='verdana' size=2>" . $yearsexp . "</font></td></tr>"; } }

« previous php.db (#15671) next »