获取多个 ID,同时 POST 多个选择选项值到下一个表单

get multiple ID while POST multiple selection option value to next form

如何在 POST 多个 selection 选项值到下一个表单时获得多个 ID?我只从数组中获取第一个 selection ID。你们能给我一些建议吗?

这是我在 select 值时的代码。

 <tr>
                  <label>Auditor: </label>
                     <select class="form-control" name="auditor[]" multiple="multiple" >
                    <?php 
                    $result =  $db->query("SELECT * FROM auditor"); 
                    while($row = mysqli_fetch_array($result))
                    {
                        echo '<option value="'.$row["auditor_name"].'">'.$row["auditor_name"].'</option>';
                        }   
                    echo "</select>";
                    ?>
                  </tr>

这是另一个代码,POST 到下一页。

$myselected         =   $_POST["auditor"];

if(count($myselected)>1){
    $auditor = implode ("','",$myselected);
    }else{
    $auditor =$myselected;
    }

$query10 = "SELECT * FROM auditor WHERE auditor_name IN ('$auditor') ";
$result10 = $db->query($query10);
$row10 = $result10->fetch_array();

?>

<form action="audit_action/audit_action.php" role="form" method="post" name="auditformdetails" onsubmit="return(validate());">  
<table width='100%' border='0' class="table">
<tr>
    <td colspan=6>Audit details</td>
    <td colspan=6>Outlet details</td>
</tr>

<tr>
<td><b>Auditor:</b></td>

<td colspan='5'>
**<?php 
    echo'<input type="hidden" name="auditor_id" value="'.$row10["id"].'">';

    foreach ($myselected as $auditor){ 
    echo $auditor."<br>\n"; 
    }
?>**
</td>

您不能将字符串与 mysql IN 子句进行比较。因此,您必须按照我在下面所写的那样将每个值与查询中的或条件连接起来。

$myselected  =   $_POST["auditor"];
$sql_cond = "";
if(count($myselected)>1){

    foreach($myselected  as $selected){
        if($sql_cond != "")
          $sql_cond.=" or auditor_name = ".$selected;
        else 
            $sql_cond.=" auditor_name = ".$selected;
    }

}else{
     $auditor =$myselected;
}

$query10 = "SELECT * FROM auditor WHERE ".$sql_cond;