I hope I haven’t duplicated this topic I’m sure it’s on here I just can’t find it.
I have a product with a bunch of sizes, the availability of these sizes is stored in a database, e.g. 0 = none in stock, 1 and more = in stock.
When not available I’d like the size to not display in a drop down. When 1 and more are available they display… I can get the size to display when 1 or more but displays “0” when = “0” Which I understand but not sure how to not display. Think I over complicated the explanation there :S
$size_available = "";
$size_6w = $row["size_6w"];
$size_7w = $row["size_7w"];
$size_8w = $row["size_8w"];
$dropdown = "<select class='product-select' name='size' id='size'>";
if ($size_6w > 0) {
$size_6w = "6w";
}
if ($size_7w > 0) {
$size_7w = "7w";
}
if ($size_8w > 0)
$size_8w = "8w";
}
$size=array("$size_6w","$size_7w","$size_8w");
foreach ($size as $size_available)
{
$dropdown .= "<option value='$size_available'>$size_available</option>";
}
$dropdown .= "\r\n</select>";
Output is a simple echo:
echo $dropdown
Should I be using an else statement? If so how would you suggest I use it to output nothing?
Thanks
Check if the size is greater than or equal to 1 and only then display the option to the user.
Here is how I would implement this: