Php 如何在阵列上(显示)多个复选框?

Php 如何在阵列上(显示)多个复选框?,php,Php,如何在阵列上(显示)多个复选框?水果包括苹果、橘子、香蕉 <?php while($row = mysql_fetch_array($result)){ $fruits = $row['fruits '] } echo "<a class ='button' href='fruits.php?fruits=".$fruits."'>click</a>"; ?> <html> <

如何在阵列上(显示)多个复选框?水果包括苹果、橘子、香蕉

<?php
   while($row = mysql_fetch_array($result)){
        $fruits = $row['fruits ']
    }
   echo "<a class ='button' href='fruits.php?fruits=".$fruits."'>click</a>"; 
?>   

 <html>   
      <input type="checkbox" name="fruits" ><?php echo $_GET['fruits'] ?><br>    
 </html>  


我想这样显示结果


您可以尝试下面的代码

<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
    <?php
        while($row = mysql_fetch_array($result)){
    ?>
    <input type="checkbox" name="fruits[]"><?php echo $row['fruits']; ?><br>
    <?php
        }
    ?>
</body>
</html>





可能是这样的

    foreach($fruits as $fruit) {
        echo '<input type="checkbox" name="fruits" '.(($_GET['fruits'] == $fruit) ? "checked" : "") .'>'. $_GET['fruits'].'<br>';    
    }
foreach($fruits as$fruit){
回显“.$”获取['fruits']。
”; }
您需要将
name=“fruits”
替换为
name=“fruits[]”
管理员检查下面的答案admin让我知道复选框将通过
while()
数据或通过
$\u获取
数据?在按钮上,需要添加哪个水果作为get参数?你把这些都放在表格里了吗?
<html>
<body>
<?php 
$fruits="your fruits array"
 while($data = mysql_fetch_array($fruits )) { 
 echo "<input type='checkbox' value='{$data['value']}'>" . $data['value'] . '</br>';
}
?>
</body>
</html>
    foreach($fruits as $fruit) {
        echo '<input type="checkbox" name="fruits" '.(($_GET['fruits'] == $fruit) ? "checked" : "") .'>'. $_GET['fruits'].'<br>';    
    }