选中多个复选框并显示多个详细信息

时间:2014-09-05 05:28:19

标签: php mysql

你能帮我解决一下这个问题吗? 如果我选中1复选框它会显示详细信息,但是当我选择单击两个或更多时,它会显示空白。我不明白这段代码有什么问题吗?它是否正确? SELECT * FROM machine_and_equipments 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>

2 个答案:

答案 0 :(得分:0)

修改以下行:

$stk = "'" . implode("','", $name) . "'"; 
//echo $stk;
$query = "SELECT * FROM machine_and_equipments where MENo IN($stk)"; 

答案 1 :(得分:0)

   <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'])){ 

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