I have a simple 2 option drop down menu which corresponds to a column in my database.
The drop down menu is not populated by the database it is just used to update the data in that 1 column. However I was wondering if it would be possible to make the selected option in the dropdown menu mirror the value currently held in the database.

<select name="attend">
  <option value="No">No</option>
  <option value="Yes">Yes</option>
</select>

So I would like to make Yes be the selected option if the field it will corresdond to in the database is yes.I know I will need to do a select query but apart from that I'm alittle clueless.

Hope someone can help.

show us you php code where the data is selected from your database

The option to be selected needs the word 'selected' after the value=xxx. In order to make this dynamic, you need a variable as part of each option as follows:

<select name="attend">
  <option value="No"<?PHP echo $selected_no; ?> >No</option>
  <option value="Yes" <?PHP echo $selected_yes; ?> >Yes</option>
</select>

Before you get to this point, you will decide if it is to be yes or no and set one variable to empty and the other one to 'selected'.

Just added in the if statement etc. Took me alittle bit of messing around with the code since it's between a <<<EOD but it now works.

Thanks Chrishea, your explanation really helped.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.