php mysql 更新 table 选项列表框

php mysql update table option listbox

我正在尝试使用值 selected 更新我的 table 到选项 select 框中,但是当我单击时它不会更新 selected 行保存。 id 是我的 table 的主键。你知道我做错了什么吗?

dovarclass.php

<form class="rnd5" action="SaveClassVariant.php" method="post" name="import" id="import">
<?php
    $Query='SELECT id,Location,`Coding`, `Amino Acid Change` AS ProtDesc,GMAF, `Coverage`, `% Frequency` AS Freq FROM mytable';
    $QueryPerform=mysqli_query($conn,$Query) or die(mysqli_error($conn));
     while($rowPanel =  mysqli_fetch_assoc($QueryPerform)) {
          $id = $rowPanel["id"];
        echo "<tr><td>&nbsp;<input name='checkbox[]' type='checkbox' id='checkbox[]' value='".$rowPanel["id"]."'&nbsp;</td>
        <td>&nbsp;<select name='list[$id]' id='list[]' size='4' multiple='multiple'>
        <option value='Classe 1'>Classe 1</option>
        <option value='Classe 2'>Classe 2</option>
        <option value='Classe 3'>Classe 3</option>
        <option value='Classe 4'>Classe 4</option>
        <option value='Classe 5a'>Classe 5a</option>
        <option value='Classe 5b'>Classe 5b</option>
        </select>
        </td>
        <td>&nbsp;".$rowPanel["Location"]."&nbsp;</td><td>&nbsp;".$rowPanel["Coding"]."&nbsp;</td><td>&nbsp;".$rowPanel["ProtDesc"]."&nbsp;</td><td>&nbsp;".$rowPanel["GMAF"]."&nbsp;</td><td>&nbsp;".$rowPanel["Coverage"]."&nbsp;</td><td>&nbsp;".$rowPanel["Freq"]."&nbsp;</td></tr>";
        }
?>
<input type="submit" name="sendEcht" value="Sauvegarder" />
</form>
<?php
mysqli_close($conn);
?>

在我的 savevariantclass.php 中,我正在尝试通过以下方式获取我的 ID:

if($_POST){

$VariantClass = $_POST['list'];
foreach(array_values($VariantClass) as $key =>$value )
{
$j=$key+1;
echo $j;
$UpdateVariantClass='UPDATE mytable SET VarClass="'.$value.'" where id='.$j.'';
mysqli_query($conn,$UpdateVariantClass) or die(mysqli_error($conn));
}
}//end of $_POST

我终于设法解决了我的问题。 要获取 ID,我使用 array_search.

$class=$_POST['list'];

foreach ($class as $value) {

$k = array_search($value,$class);
$sql='UPDATE mytable SET VarClass='.$value.' where id='.$k.'';
echo $sql.'<br/>';

}