0

Lets say $cat is 5, I want it to have the forum with ID 5 selected but it wont. I have a forum with ID 5. Shouldn't this work?

<select name="category" id="category">
foreach($db->query("SELECT name FROM forums ORDER BY disp_position ASC") as $row) {
   if ($cat == $row['id']) {
      echo '<option value="'.$row['id'].'" selected>'.$row['name'].'</option>';
   } else {
      echo '<option value="'.$row['id'].'">'.$row['name'].'</option>';
   }
}
</select>
4

1 回答 1

0

You should add id field in your select.

SELECT id, name FROM forums ORDER BY disp_position ASC
于 2013-07-21T18:32:28.637 回答