Jump to content

Quantity drop-down problem


timmah1

Recommended Posts

In my database is a field for qty(quantity).

 

I have the form with qty as a drop down, but I only want whatever is in the database to show in the drop down.

 

For example, if there are only 5 of a particular item in the database, I only want the user to be able to select up to 5 qty, and if there are only 2, I only want them to be able to select 2 as the qty.

 

How do I go about doing this?

 

I have my size drop down like this

<select name="size">
<?php
foreach ($size as $value) {
?>
<option value="<?php echo $value;?>"><?php echo $value;?></option>
<?php
} 
?></select>

But since the values are stored like sm,med,lg that's pretty simple to do.

 

I tried foreach, but since it's just a number, there is only 1 number, and I am at a total lost with this one.

 

Thank you in advance.

Link to comment
https://forums.phpfreaks.com/topic/223106-quantity-drop-down-problem/
Share on other sites

Use the number as the second parameter in range to create an array, then you can use a foreach() to build the <option> list.

 

As in


$list = range(0, $db['field']);
echo '<select>';
foreach( $list as $val ) {
    echo "<option value=\"$val\">$val</option>";
}
echo '</select>';
[/code]

 

Make sense?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.