/    Sign up×
Community /Pin to ProfileBookmark

MySQL result into a multidimensional array

Hi I may not have explained myself so clear before so il try and reword my dilema. A product has a number of attributes i.e. productID, description, Image, price e.t.c. Now at the moment I have put the imgLoc into an array called $imgLoc[] which is displayed through a number of layers. However I now need the price and description to be displayed through the layers i.e. in image1 the image is displayed as well as the description and the price. I thought that i would simply have to rewrite the sql statement and then write the arrays like $price[]=$price; and $description[]=$description; however when i write this it simply doesnt display anything. Heres the full code that ive written and is working at the moment i.e. only displaying the image. Has anyone got any ideas? thanks

[code]<?php
include(‘../../../include.html’);
include(‘../../../dressingroom.inc’);

echo”<html>”;
echo”<head>”;

echo”<link rel=’stylesheet’ href=’../../../dressingroom.css’ type=’text/css’>”;
echo”</head>”;
echo”<body>”;

$startID=$_REQUEST[‘id’];

$sql = “select MAX(productID) as produID from Products”;
$result = mysql_query($sql) or die (“ERROR, NO PRODUCTS AVAILABLE!!”);
$row = mysql_fetch_array($result);
$maxProd = $row[‘produID’];

$found = 0;

while ($startID <= $maxProd && $found < 4){
$sql = “select price, imgLoc from Products where productID=’$startID’ and category=’Dresses'”;
$result = mysql_query($sql) or die (“ERROR!!”);
$nrows=mysql_num_rows($result);
if ($nrows != 0){
$found++;
$row = mysql_fetch_array($result);
extract($row);
$img[]=$imgLoc;
$ids[]=$startID;
}
$startID++;
}

$arraySize=sizeof($img);

echo”
<div id=’navigation’>

<div id=’home’><img src=’../../IMAGES/home.jpg’ width=’16’ height=’14’ border=’0′></div>
<div id=’homelabel’ class=’fourthtitle’><a href=’FrontPage.php’ style=’text-decoration:none’>Home</a></div>
<div id=’arrow1′><img src=’../../IMAGES/arrow.jpg’ width=’12’ height=’14’ border=’0′></div>
<div id=’itemlabel’ class=’fourthtitle’>Dresses</div>

</div>”;

echo “<div id=’products’>”;
echo “<div id=’producttitle’><div id=’producttitle2′ class=’secondtitle’>Dresses</div></div>”;
if ($arraySize >= 1){
echo “<div id=’image1′><div id=’productdescription’ class=’thirdtitle’></div><a href=’../Product_View.php?id=$ids[0]’><img src=’../../IMAGES/$img[0]’ width=’110′ height=’150′ border=’0′></a></div>”;
if ($arraySize >= 2){
echo “<div id=’image2′><div id=’productdescription’ class=’thirdtitle’></div><a href=’../Product_View.php?id=$ids[1]’><img src=’../../IMAGES/$img[1]’ width=’110′ height=’150′ border=’0′></a></div>”;
if ($arraySize >= 3){
echo “<div id=’image3′><div id=’productdescription’ class=’thirdtitle’></div><a href=’../Product_View.php?id=$ids[2]’><img src=’../../IMAGES/$img[2]’ width=’110′ height=’150′ border=’0′></a></div>”;
if ($arraySize == 4){
echo “<div id=’image4′><div id=’productdescription’ class=’thirdtitle’></div><a href=’../Product_View.php?id=$ids[3]’><img src=’../../IMAGES/$img[3]’ width=’110′ height=’150′ border=’0′></a></div>”;
}
}
}
echo “<div id=’next’ class=’thirdtitle’><a href=’#’ onClick=’history.go(-1)’>Previous</a>&nbsp; | &nbsp;<a href=’dresses.php?id=$startID’>Next</a></div>”;
}
else{
echo “<center><b>Unfortunately there are no more Shirts available at this current time</b><br><br>Please click <a href=’#’ onClick=’history.go(-1)’>HERE</a> to go back, or <a href=’shirts.php?id=1′>HERE</a> to search from Shirts beginning”;
}
echo”</div>”;
?>

<br>

</body>

</html>[/code]

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @cs3mw spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...