Re: [PHP] Multidimentional array problems
On 4/3/06, Mace Eliason <[EMAIL PROTECTED]> wrote: > This is what I am doing and the output (for testing) seems correct > while($row=mysql_fetch_array($result)) > { > $banner= array($arrayIndex => $row); > > echo $banner[$arrayIndex]["image"]. ""; > echo $banner[$arrayIndex]["url"]. ""; > echo $banner[$arrayIndex]["display_type"]. ""; > $arrayIndex++; > } > Tom is correct, you're overwriting $banner each time. While the following is a bit verbose (Tom's assignment step is all you need), this might help to show what's happening: [code] $banner_array = array(); while ($row = mysql_fetch_array($result)) { $banner_array[] = array( "url" => $row["url"], "image" => $row["image"], "display_type" => $row["display_type"] ); } [/code] > $value=0; > while($value < $number_of_banners_db ) > { > echo $banner[$value]["url"]. ""; > echo $banner[$value]["image"]. ""; > echo $banner[$value]["display_type"]. ""; > } Here you're also not incrementing your loop counter. Try this: [code] foreach($banner_array as $banner) { echo $banner["url"] . ""; echo $banner["image"] . ""; echo $banner["display_type"] . ""; } [/code] HTH, John W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Multidimentional array problems
Hi, Tuesday, April 4, 2006, 8:37:18 AM, you wrote: ME> Hi, ME> I am trying to read form a database and place everything in a ME> multi-dimentional array ME> This is what I am doing and the output (for testing) seems correct ME> while($row=mysql_fetch_array($result)) ME> { ME> $banner= array($arrayIndex => $row); ME> echo $banner[$arrayIndex]["image"]. ""; ME> echo $banner[$arrayIndex]["url"]. ""; ME> echo $banner[$arrayIndex]["display_type"]. ""; ME> $arrayIndex++; ME> } ME> When I try and use ME> $value=0; ME> while($value < $number_of_banners_db ) ME> { ME> echo $banner[$value]["url"]. ""; ME> echo $banner[$value]["image"]. ""; ME> echo $banner[$value]["display_type"]. ""; ME> } ME> I only get the last set of values that where entered into the array. I ME> want to be able to pull all the values out ME> $banner[0]['url'] ME> $banner[1]['url'] ME> $banner[2]['url'] etc. ME> I don't use arrays much and I have been going thru my books but I still ME> can't seem to get it to work. ME> Thanks You are creating a new $banner each time it loops. It should be like this: $banner = array(); $arrayIndex = 0; while($row=mysql_fetch_array($result)) { $banner[$arrayIndex] = $row; echo $banner[$arrayIndex]["image"]. ""; echo $banner[$arrayIndex]["url"]. ""; echo $banner[$arrayIndex]["display_type"]. ""; $arrayIndex++; } -- regards, Tom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Multidimentional array problems
I am trying to read form a database and place everything in a multi-dimentional array This is what I am doing and the output (for testing) seems correct while($row=mysql_fetch_array($result)) { $banner= array($arrayIndex => $row); echo $banner[$arrayIndex]["image"]. ""; echo $banner[$arrayIndex]["url"]. ""; echo $banner[$arrayIndex]["display_type"]. ""; $arrayIndex++; } What are you setting $arrayIndex to initially (before the while loop starts?) When I try and use $value=0; while($value < $number_of_banners_db ) { echo $banner[$value]["url"]. ""; echo $banner[$value]["image"]. ""; echo $banner[$value]["display_type"]. ""; } I only get the last set of values that where entered into the array. I want to be able to pull all the values out $banner[0]['url'] $banner[1]['url'] $banner[2]['url'] etc. I don't use arrays much and I have been going thru my books but I still can't seem to get it to work. Try a print_r($banner) and see what it looks like -philip -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Multidimentional array problems
Hi, I am trying to read form a database and place everything in a multi-dimentional array This is what I am doing and the output (for testing) seems correct while($row=mysql_fetch_array($result)) { $banner= array($arrayIndex => $row); echo $banner[$arrayIndex]["image"]. ""; echo $banner[$arrayIndex]["url"]. ""; echo $banner[$arrayIndex]["display_type"]. ""; $arrayIndex++; } When I try and use $value=0; while($value < $number_of_banners_db ) { echo $banner[$value]["url"]. ""; echo $banner[$value]["image"]. ""; echo $banner[$value]["display_type"]. ""; } I only get the last set of values that where entered into the array. I want to be able to pull all the values out $banner[0]['url'] $banner[1]['url'] $banner[2]['url'] etc. I don't use arrays much and I have been going thru my books but I still can't seem to get it to work. Thanks -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php