我正在创建一个带有四个下拉选择框的游戏启动窗体。每个框将用于选择一个播放器(播放器从mysql数据库中用户的朋友列表中提取)。我使用php动态填充选项列表(潜在玩家)。
每个项目都有一个唯一的名称和id。
有没有办法删除已经从其他下拉列表中选择的选项?我可以在这里找到javascript的例子,但在php中没有。
我已经插入了我正在使用的表单代码$选项只是一个用户名数组(注意:我的if语句完全是猜测。我绝对不是一个经验丰富的程序员。)
<form method="POST" action="game.php">
<select id="1stPlayer" name="1stPlayer" required>
<option value="" disabled="disabled" selected="selected">Please select Player 1 (Team 1)</option>
<?php
$first = $_GET["1stPlayer"];
$second = $_GET["2ndPlayer"];
$third = $_GET["3rdPlayer"];
$fourth = $_GET["4thPlayer"];
echo implode(",",array_unique($option));
foreach ($option as $row) {
$value = $row;
if ($value != $second && $value != $third && $value != $fourth ) {
echo '<option value="'. $value .'">'. $value .'</option>';
};
};
?>
</select>
<select id="2ndPlayer" name="2ndPlayer" required>
<option value="" disabled="disabled" selected="selected">Please select Player 1 (Team 1)</option>
<?php
$first = $_GET["1stPlayer"];
$second = $_GET["2ndPlayer"];
$third = $_GET["3rdPlayer"];
$fourth = $_GET["4thPlayer"];
echo implode(",",array_unique($option));
foreach ($option as $row) {
$value = $row;
if ($value != $first && $value != $third && $value != $fourth ) {
echo '<option value="'. $value .'">'. $value .'</option>';
};
};
?>
</select>
<select id="$third" name="$third" required>
<option value="" disabled="disabled" selected="selected">Please select Player 1 (Team 1)</option>
<?php
$first = $_GET["1stPlayer"];
$second = $_GET["2ndPlayer"];
$third = $_GET["3rdPlayer"];
$fourth = $_GET["4thPlayer"];
echo implode(",",array_unique($option));
foreach ($option as $row) {
$value = $row;
if ($value != $second && $value != $first && $value != $fourth ) {
echo '<option value="'. $value .'">'. $value .'</option>';
};
};
?>
</select>
<select id="4thPlayer" name="4thPlayer" required>
<option value="" disabled="disabled" selected="selected">Please select Player 1 (Team 1)</option>
<?php
$first = $_GET["1stPlayer"];
$second = $_GET["2ndPlayer"];
$third = $_GET["3rdPlayer"];
$fourth = $_GET["4thPlayer"];
echo implode(",",array_unique($option));
foreach ($option as $row) {
$value = $row;
if ($value != $second && $value != $third && $value != $first ) {
echo '<option value="'. $value .'">'. $value .'</option>';
};
};
?>
</select>
<input type="submit" name="startGame" id="single_game_button" value="Start Game">
</form>
暂无答案!
目前还没有任何答案,快来回答吧!