这是另一个。同一天两次。我正在尝试设置 4 个选择框,如果它们等于 enSlot 的值,则显示基于 Target1-4 中的值选择的选项。
echo "<select id='target".$row['paSlot']."' size='1' style='width:90px;'>";
$query = "SELECT * FROM enemy WHERE enChar = ".$_SESSION['chNum']." ORDER BY enSlot";
$result1 = mysql_query($query, $_SESSION['connect']) or die('Error 150: '.mysql_error());
while ($row1 = mysql_fetch_array($result1)) {
$s = "";
if ($_GET['Target1'] == $row1['enSlot']) {
$s = "selected='selected'";
}
if ($_GET['Target2'] == $row1['enSlot']) {
$s = "selected='selected'";
}
if ($_GET['Target3'] == $row1['enSlot']) {
$s = "selected='selected'";
}
if ($_GET['Target4'] == $row1['enSlot']) {
$s = "selected='selected'";
}
echo "<option value=".$row1['enSlot']." ".$s.">".$row1['enSlot'].". ".$row1['enRace'];
}
echo "</select>";
我用这个运行它:
Target1 = 1, Target2 = 2, Target3 = 3, Target4 = 4 敌人有 4 条记录,enSlot = 1 - 4
当它执行时,我得到所有 4 个选择框显示 Target4 的最后一个值被选中。