嗨,你能帮我看看这是什么问题吗? 如果我选中 1 个复选框,它会显示详细信息,但当我选择单击两个或多个复选框时,它会显示空白。我不明白这段代码是否有问题?它是否正确? SELECT * FROM machine_and_equipments where MENo IN('$stk') 或者可能还有其他代码要做?
<form action="CHECKBOX.php" method="post">
<input type="hidden" name="color" value="0"/>
<?php
include('function.php');
$name = isset($_POST['stick'])?$_POST['stick']:NULL;
if(isset($_POST['stick'])){
foreach ($name as $stk){
//checkboxes
$stk = implode(',', $name);
//echo $stk;
$query = "SELECT * FROM machine_and_equipments where MENo IN('$stk')";
$result = mysql_query($query) or die (mysql_error());
while($query_row = mysql_fetch_assoc($result)){
$controlnumber = $query_row['MENo'];
$assetname = $query_row['machine_equipments_name'];
$location = $query_row['Location'];
?>
<br>
<table>
<tr>
<td>
<?php echo $controlnumber;?>
</td>
<td>
<?php echo $assetname;?>
</td>
<td>
<?php echo $location;?>
</td>
</td>
</tr>
</table>
<?php }}}
?>
KMP-AC1-001<input type="checkbox" name="stick[]" id="stick" value="KMP-AC1-001"><br />
KMP-AC2-002<input type="checkbox" name="stick[]" id="stick" value="KMP-AC2-002"><br />
KMP-AC3-003<input type="checkbox" name="stick[]" id="stick" value="KMP-AC3-003"><br />
KMP-AC4-004<input type="checkbox" name="stick[]" id="stick" value="KMP-AC4-004"><br />
KMP-RF1-005<input type="checkbox" name="stick[]" id="stick" value="KMP-RF1-005"><br />
KMP-RF2-006<input type="checkbox" name="stick[]" id="stick" value="KMP-RF2-006"><br />
KMP-EL2-009<input type="checkbox" name="stick[]" id="stick" value="KMP-EL2-009"><br />
<input type="submit" value="submit">
</form>
最佳答案
修改以下行:
$stk = "'" . implode("','", $name) . "'";
//echo $stk;
$query = "SELECT * FROM machine_and_equipments where MENo IN($stk)";
关于php - 选中多个复选框并显示多个详细信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25679126/