【发布时间】:2016-01-01 15:38:27
【问题描述】:
如何在将多项选择选项值发布到下一个表单时获取多个 ID?我只从数组中获取第一个选择 ID。大家可以给我建议吗?
这是我选择值时的代码。
<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>
【问题讨论】:
-
你能解释一下你想要什么输出吗?
-
嗨@sandeepsure,输出例如:ROBERT ALAN ALVIN 但是,当发布数据时,它只显示第一个 ROBERT“id”;其他两个 ALAN 和 ALVIN id 未显示,当我传递表单时,它只将第一个 ROBERT id 存储到数据库中。
-
print_r($myselected )告诉我结果。 -
@sandeepsure Array ([0] => Michiyo (WY) [1] => Shiow Yong (BUN) [2] => Seok Hoon (SH))
标签: php arrays implode multipleselection