herghost Posted March 12, 2010 Share Posted March 12, 2010 Hi All, I have a table called featurelist which contains about 8 fields, however I just want to grab 2, id and feature_name and display these on a dropdown list in another form. So Basically: This products features: <option>1.Red</option> <option>2.Blue</option> etc.. However what I want saved into the new database is just the id. How would I go about this? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/194989-populating-drop-down-from-database/ Share on other sites More sharing options...
Adam Posted March 12, 2010 Share Posted March 12, 2010 Your PHP would need to look something like: // run your query while ($row = mysql_fetch_assoc($query)) { echo '<option value="{$row['id']}">{$row['feature_name']}</option>'; } That way the value attribute contains the ID and once the form is submitted that ID will be passed on. Quote Link to comment https://forums.phpfreaks.com/topic/194989-populating-drop-down-from-database/#findComment-1025118 Share on other sites More sharing options...
herghost Posted March 12, 2010 Author Share Posted March 12, 2010 Thanks, However I have this: <?php $query = "SELECT * FROM product_features"; $result = mysql_query($query); while ($list = mysql_fetch_assoc($result)) { echo '<dt><label for="product_features_id">Features Package:</label></dt>'; echo '<dd><select size="1" name="product_features_id">'; echo '<option value="'; echo $list['id']; echo '">'; echo $list['id']; echo ' '; echo $list['name']; echo '</option>'; echo '</select>'; } ?> As there is more than one result in the database, it is creating a dropdown box for each value instead of putting all values in one dropdown box? Quote Link to comment https://forums.phpfreaks.com/topic/194989-populating-drop-down-from-database/#findComment-1025122 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.