View Full Version : combo

03-10-2007, 03:46 PM
I have a combo box :

<select name="stock" id="stock">
<option value="In Stock">In Stock</option>
<option value="Not in Stock">Not in Stock</option>
<option value="Discontinued">Discontinued</option>

I am connecting to the database and i want to display the results in a form and change the value of the combo box to the one value in the database for that record.

How would i set the combo box to the correct value using php.
Im not sure if this is a html or a php question

03-10-2007, 03:50 PM
Both actually, you just have to add "selected" inside of the option tag. You can use an if() switch or ternary operator to do it with, it's pretty straight-forward.

<option value="1"<?=!empty($selected) ? ' selected' : '';?>>Selection</option>

03-10-2007, 04:10 PM
The problem i have is i dont know where i should do an if statement and how to construct it to check each option for it's value.
would i do it within the <option> tag or above the <select> tag and how do you refer to the html tags within php?

I havent a clue how to do this!


03-10-2007, 04:15 PM
I just showed you in my previous post. You have to make one for each option.