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>
您应该在选择中添加ID字段 。
SELECT id, name FROM forums ORDER BY disp_position ASC
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.