jericho morales
jericho morales

Reputation: 19

how to display mysql data using drop down?

here is what i came up, i could insert a data into my "gender" field, but when I'm in edit/update page, i want the "gender" field only displays "Select One" value, not "male/Female"

thanks in advance

<form action='#' method='post' border='0'>
<table>
 <tr>
  <td>
   <select name="gender" id="gender">
   <option>Select One</option>
   <option>Male</option>
   <option>Female</option>
   </select>
  </td>
 </tr>
 <td>
  <input type='hidden' name='id_number' value='<? php echo $id_number ?>' />
  <input type='hidden' name='action' value='edit' />
  <input type='submit' value='Edit' />
 </td>
</table>
</form>

Upvotes: 0

Views: 985

Answers (2)

GautamD31
GautamD31

Reputation: 28763

Simply import the $gender value from the db into the edit page and then add this :

<select name="gender" id="gender">
    <option>Select One</option>
    <option <?if $gender=="Male" echo 'selected="selected"'?>>Male</option>
    <option <?if $gender=="Female" echo 'selected="selected"'?>>Female</option>
</select>

Thats it friend.I hope it will useful for you much

Upvotes: 0

Ken Bloom
Ken Bloom

Reputation: 58770

You have to add an attribute named selected="selected" to the <option> tag that you want selected by default.

Upvotes: 1

Related Questions