Jump to content

Edit Form & Drop Down box issues


iceblox

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.