Skip to content
Advertisement

display multiple value of same column in mysqli php

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

How its looking now[![My table.[![Expected result]1]2

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']; ?>"  >
                &nbsp;&nbsp; <?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']; ?>"  >
                &nbsp;&nbsp;
                 <?php foreach($column as $value)echo $value['name']; ?></a>
            <?php } ?>  
            </div> 

Getting this error after trying code

Getting error after my putting new code in page

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; ?>" >
        &nbsp;&nbsp;<?php echo $value; ?>
        </a>
<?php } ?>  
</div> 
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement