0

I am trying to use a dropdown list and set the value to the one in the databse.

For example if the database holds "Website" I would want this to be the selected option on the dropdown form.

See below code, I have repeated this for each of my products

if($product['product'] = 'Website'){
echo"
<div class='form-group'>
<label for='mail_message'>Product<font color='red'>*</font></label>
<select name='product' id='product' class='form-control' required>
<option value='Website'  selected='selected'>Website</option>
<option value='CMS'>CMS</option>
<option value='Domain'>Domain</option>
<option value='Hosting'>Hosting</option>
</select>
</div>
"; }  

When i run this code, i have numerous dropdowns showing with each of my products showing as the selected value for each

Can anyone help? (NB)

2
  • please add some more of your code, for example the code that gives you the results(sql code) and basicly everything that can have something to do with this, also since you are talking about a database a tiny bit more information about how the database looks like would be handy Commented Mar 8, 2015 at 13:44
  • You need to construct the <option...> line to either have selected or not. Commented Mar 8, 2015 at 22:03

1 Answer 1

1

if i am correct then you want to target the results from the database that has "website" in them right?

then you have to edit your sql query to only select those so the query would become something like this:

"SELECT * FROM `table_name` FROM `database_name` WHERE `type`='website'"

please do note that you have to replace 'table_name' to the actual table name, database_name to the actual database name and 'type' to the actual table key.

if the query is like this then you wont have to check if($product['product'] = 'Website') because this would always be true

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.