Why won't it highlight the variable in the SELECT dropdown?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Why won't it highlight the variable in the SELECT dropdown?

Post by simonmlewis »

Code: Select all

$cat = $_POST['cat'];
if ($cat == NULL) { $cat = 'Glass Beads Silver'; }

<form method='post' action='index.php?page=selector&menu=home&bid=$bid&brc=$brc'>You are in <select name='cat' class='selectordropdown'>";
$result = mysql_query ("SELECT DISTINCT category FROM products WHERE pause = 'off' AND (category = 'Glass Beads' || category = 'Glass Beads Silver' || category = 'Silver Charms') ORDER BY category");
while ($row = mysql_fetch_object($result))
  {
   if ($row->category == $cat) { $selected = "selected='selected' style='font-weight: bold'";}
      elseif ($row->category != $cat) { $selected = "";}
      
   echo "<option value='$row->category' $selected>$row->category</option>";      
	}
	mysql_free_result($result);
echo "<input type='submit' value='Choose Category'></form>";
This should be setting "Glass Beads Silver" as the "selected='selected'" option ...... shouldn't it?

The super-strange thing about this is - on my localhost server on my laptop, it will do it. Bearing in mind it's the second in the list, it will set that as the 'selected' item, but when I view it on a 'live' server both on Firefox and IE8, neither 'select' it.

Anyone know why? And if so, anyone so a solution?

S.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
Post Reply