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
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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.