我想在下拉列表中获得战斗名单,这是我管理的。但现在我想保持其中一个被选中。但我找不到与我的$行比较的判断权。
非常感谢
< ?php
echo " < select name = 'battle' > ";
while (($rows = mysqli_fetch_array($result)) != null)
{
echo "< option value = '{$rows['battle_number']}'";
if ($result['battle_number'] == $rows['battle_number'])
echo "selected = 'selected'";
echo ">{$rows['name']}</option>";
}
echo "< /select>";
? >
答案 0 :(得分:1)
更正和简化的代码:
<?php
echo '<select name="battle">';
while ($rows = mysqli_fetch_array($result)) {
$selected = ($result['battle_number'] == $rows['battle_number']) ? 'selected="selected"' : '';
echo '<option value = "'.$rows['battle_number'] . '" ' . $selected. '>' . $rows['name'] . '</option>';
}
echo '</select>';
?>