我想在复选框中显示值。我在数据库中有多个值,如上图所示。请看一看。我希望不同复选框中的值不在同一个复选框中
我正在尝试的代码
<div class="list-group">
<h3>Name</h3>
<?php
$query = "select distinct(name) from info_user where user_status = '1'";
$rs = mysqli_query($con,$query) or die("Error : ".mysqli_error());
while($color_data = mysqli_fetch_assoc($rs)){
?>
<a href="javascript:void(0);" class="list-group-item">
<input type="checkbox" class="item_filter colour" value="<?php echo $color_data['name']; ?>" >
<?php echo $color_data['name']; ?></a>
<?php } ?>
</div>
我自己尝试了什么
<div class="list-group">
<h3>Name</h3>
<?php
$column = array();
$query = "select name from info_user where user_status = '1'";
$rs = mysqli_query($con,$query) or die("Error : ".mysqli_error());
while($color_data = mysqli_fetch_assoc($rs)){
$column[] = $color_data['name'];
?>
<a href="javascript:void(0);" class="list-group-item">
<input type="checkbox" class="item_filter colour" value="<?php foreach($column as $value)echo $value['name']; ?>" >
<?php foreach($column as $value)echo $value['name']; ?></a>
<?php } ?>
</div>
尝试代码后出现此错误
答案 0 :(得分:1)
您可以尝试这种方式,更新您的代码
<div class="list-group">
<h3>Name</h3>
<?php
$column = array();
$query = "select distinct(name) from info_user where user_status = '1'";
$rs = mysqli_query($con, $query) or die("Error : " . mysqli_error());
while ($color_data = mysqli_fetch_assoc($rs)) {
$column = array_merge($column, explode(',',$color_data['name']));
}
// to remove repeated names
$column = array_filter($column);
?>
<a href="javascript:void(0);" class="list-group-item">
<input type="checkbox" class="item_filter colour" value="<?php
foreach ($column as $value) {
echo $value;
?>">
<?php
echo $value;
}
?>
</a>
</div>
答案 1 :(得分:1)
我认为这就是你所需要的。
merge