Jump to content

Recommended Posts

Hi Guys,

 

Im still a PHP newbie and i have a bit of script which allows me to edit stuff in my database but im trying to get it to work with a drop down box. So that when i use the page it will automatically select that option in the drop down. If that makes sense?

 

I have this but it is selecting every option...

 

here is the code...

 

        $manufacturer="<option>Select a Manufacturer</option>";
$result = $db->sql_query("SELECT * FROM manf ORDER BY manfname ASC");
while($row = $db->sql_fetchrow($result))
{
	$selected="";
	if($row["manfid"]==$manfid)
		$selected = " selected=\"selected\"";
	$manufacturer.="<option$selected value=\"".$row["manfname"]."\">".$row["manfname"]."</option>";
}

 

 

Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/52682-edit-form-drop-down-box-issues/
Share on other sites

Sorry i probably didnt explain it well. The edit function is to edit a mobile phone review, the drop down box has the manufacturers in and the only one i want selected is the manufacturer that relates to the mobile being edited. Does that sound clearer?

 

Cheers

Hi Guys,

 

Im still a PHP newbie and i have a bit of script which allows me to edit stuff in my database but im trying to get it to work with a drop down box. So that when i use the page it will automatically select that option in the drop down. If that makes sense?

 

I have this but it is selecting every option...

 

here is the code...

 

        $manufacturer="<option>Select a Manufacturer</option>";
$result = $db->sql_query("SELECT * FROM manf ORDER BY manfname ASC");
while($row = $db->sql_fetchrow($result))
{
	$selected="";
	if($row["manfid"]==$manfid)
		if($manfid==$_POST['MANFID']) //<---assumes selected on previous screen
		{$selected = " selected=\"selected\"";}
		else{$selected = "";}
	$manufacturer.="<option$selected value=\"".$row["manfname"]."\">".$row["manfname"]."</option>";
}

 

 

Any ideas?

Here comes CSS to the rescue

 

adapt the following to your script

 

<select>
<option>Sony Ericcson</option>
<option style="background-color:#FFFF00">Motorola</option>
<option>Nokia</option>
</select>

 

Tested it on Opera 9+, FF2.0, IE7 and IE6, I'm guessing this is what you want...

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.