timmah1 Posted January 1, 2011 Share Posted January 1, 2011 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. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted January 1, 2011 Share Posted January 1, 2011 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? Quote Link to comment Share on other sites More sharing options...
timmah1 Posted January 1, 2011 Author Share Posted January 1, 2011 Thank you so much. I didn't even think of range, yet I use this for my years $current = date("Y"); $future = date("Y", strtotime('+5 years')); $years = range ($current, $future); Doh! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.