Re: Multidimentional array problems
| From: | Tom Rogers | Date: | Tue, 04 Apr 2006 00:02:43 +0000 |
| Subject: | Re: Multidimentional array problems | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-233167@lists.php.net to get a copy of this message | ||
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"]. "<br>";
ME> echo $banner[$arrayIndex]["url"]. "<br>";
ME> echo $banner[$arrayIndex]["display_type"]. "<br>";
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"]. "<br>";
ME> echo $banner[$value]["image"]. "<br>";
ME> echo $banner[$value]["display_type"]. "<br>";
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"]. "<br>";
echo $banner[$arrayIndex]["url"]. "<br>";
echo $banner[$arrayIndex]["display_type"]. "<br>";
$arrayIndex++;
}
--
regards,
Tom