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

时间:2018-03-13 06:30:47

标签: php

如何(显示)阵列上的多个复选框?水果包括苹果,橙子,香蕉。

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

我想像这样显示结果

I want to display the result like this

4 个答案:

答案 0 :(得分:0)

您可以尝试以下代码。

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

答案 1 :(得分:0)

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

答案 2 :(得分:0)

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

答案 3 :(得分:0)

可能是这样的。

    foreach($fruits as $fruit) {
        echo '<input type="checkbox" name="fruits" '.(($_GET['fruits'] == $fruit) ? "checked" : "") .'>'. $_GET['fruits'].'<br>';    
    }