djrichwz Posted December 7, 2008 Share Posted December 7, 2008 I have created a form which inserts a value into the database from a drop down box, this works fine the problem comes when i try to edit that value using an edit form within my edit script. I want to create the dropdown box say for instance option 1 option 2 option 3 If one of the options above is the same as one in the db I want that to be the default selected value for the drop down box. I do not really know where to begin with the code for this. I have been figure this out for ages. Please can someone help ??? Quote Link to comment Share on other sites More sharing options...
john-formby Posted December 7, 2008 Share Posted December 7, 2008 Hi, I do this on one of my sites. Have a look at the following code: <div class="r1"><label>Difficulty Rating</label></div> <div class="r2"><select class="select1" name="rdiffrate">'; $sql3 = mysql_query("SELECT * FROM tbldiffrate ORDER BY drID ASC"); $num_rows3 = mysql_num_rows($sql3); if ($num_rows3 == 0) { echo '<option value="">No Difficulty Ratings</option>'; } else { echo '<option value="">Please Select</option>'; while($row3 = mysql_fetch_array($sql3)) { echo '<option ' . ($rdiffrate==$row3['drID'] ? 'selected' : '') . ' value="'.$row3['drID'].'">'.$row3['rdiff'].'</option>'; } } echo '</select> </div></div>'; I have another sql query higher up the page that has the value of $rdiffrate: if($page == 'edit') { $sql2 = mysql_query("SELECT * FROM tblroute WHERE rID = '$rID'"); $row2 = mysql_fetch_array($sql2); $rtitle = $row2['rtitle']; $rdiffrate = $row2['rdiffrate']; } Hope this helps, John Quote Link to comment Share on other sites More sharing options...
djrichwz Posted December 7, 2008 Author Share Posted December 7, 2008 thanks I will try that when I get back from work probably tommorow now. I will let you know If it works ok but I think that is doing what I need to do. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.