I want to display value in checkbox. i have multiple value in database as shown in pic above. please have a look. I want value in different checkbox not in same checkbox
Code I am trying
<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>
and what i tried by myself
<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>
Getting this error after trying code
Advertisement
Answer
I think this is what you need.
<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); while ($color_data = mysqli_fetch_assoc($rs)) { $column = array_merge($column, explode(',', $color_data['name'])); } $column = array_unique($column); foreach ($column as $value) { ?> <a href="javascript:void(0);" class="list-group-item"> <input type="checkbox" class="item_filter colour" value="<?php echo $value; ?>" > <?php echo $value; ?> </a> <?php } ?> </div>