Jump to content

Recommended Posts

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

 

Link to comment
https://forums.phpfreaks.com/topic/194989-populating-drop-down-from-database/
Share on other sites

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.

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?

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.