Jump to content

editing values generated bythe db in a dropdown box


djrichwz

Recommended Posts

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  ???

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.