Hi,
I need to populate a drop down box with size and colour values from my db. I have got it working but it just seems to be too clunky. I'm going to be marked on it and so would like to know where I'm going wrong. What I do not like is that I loop through the array and then need to tell it to go one more time.
Thanks in advance.
$query3 = "SELECT size, in_stock, colour, itemline_id
FROM itemline
WHERE item_id = '" . $row['item_id'] . "'";
$result3 = mysql_query($query3);
$row3 = mysql_fetch_array($result3);
echo "test" . mysql_num_rows($result3);
echo "<form method='post' action='ppp.php'><select name='id'>";
$size = $row3['size'];
$colour = $row3['colour'];
$in_stock = $row3['in_stock'];
$id = $row3['itemline_id'];
while ($row3 = mysql_fetch_array($result3)) {
if ($in_stock != 0){
echo "<option value='" . $id . "'>Size: " . $size . " -- Colour: " . $colour . " -- In Stock: " . $in_stock . "</option>";
}
else{
echo "<option disabled='disabled'>Size: " . $size . " -- Colour: " . $colour . " -- OUT OF STOCK</option>";
}
$size = $row3['size'];
$colour = $row3['colour'];
$in_stock = $row3['in_stock'];
$id = $row3['itemline_id'];
}
if ($in_stock != 0){
echo "<option value='" . $id . "'>Size: " . $size . " -- Colour: " . $colour . " -- In Stock: " . $in_stock . "</option>";
}
else{
echo "<option disabled='disabled'>Size: " . $size . " -- Colour: " . $colour . " -- OUT OF STOCK</option>";
}
echo "</select><input name='action' type='hidden' value='addtocart' /><input type='hidden' name='id' value ='".$row['item_id']."' /><p><input type='submit' value='Add to basket' ></p></form>";