dtf579777 2015-10-05 03:26
浏览 148
已采纳

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

how can I get multiple ID while POST multiple selection option value to next form? I only get the first selection ID from array. Can you guys can suggest any ideas to me?

here is my code when select the value.

 <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>

here is another code while POST to the next page.

$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>
"; 
    }
?>**
</td>
  • 写回答

1条回答 默认 最新

  • doufubu2518 2015-10-05 06:01
    关注

    You can not compare string with mysql IN Clause. So, you have to connect each of your value with or condition in query as i written below.

    $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;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料