如何存储循环生成的多重复选复选框的值。 我已经看到很多方法可以从复选框中获取值,但是如果它是以这种方式生成的话:
if(mysql_num_rows($result) > 0)
{
while($row = mysql_fetch_assoc($result))
{
echo'<div class="checkbox ">
<label>
<input type="checkbox" id="chkbox" name="requirement_name[]" value="'.$row['requirement_id'].'">
'.$row['requirement_name'].'
</label>
</div>';
}
}
我能够使用此代码,但它只显示检查的数量和检查的内容:
<?php
if(isset($_POST['submit'])){
if(!empty($_POST['requirement_name'])) {
// Counting number of checked checkboxes.
$checked_count = count($_POST['requirement_name']);
echo "You have selected following ".$checked_count." option(s): <br/>";
// Loop to store and display values of individual checked checkbox.
foreach($_POST['requirement_name'] as $selected) {
echo "<p>".$selected ."</p>";
}
}
else{
echo "<b>Please Select Atleast One Option.</b>";
}
}
?>