please me solve issue. i'm trying populate checkboxes according information database working problem is unknown reasons duplicating checkboxes.
<li class="treeview"> <a href="#"><i class="fa fa-tachometer"></i> <span>dashboard</span></a> <ul class="treeview-menu"> <li style="padding-left: 5px;"> <a href="#"><i class="active fa fa-search"></i> <span>searches</span> <i class="fa fa-angle-left pull-right"></i></a> <ul class="treeview-menu"> <div id="checkbox-container"> <li style="padding-left: 10px;"> <input type="checkbox" id="selectall" onclick='selectall(this.checked)'/> <span style="color: #fff;">select all</span> </li> <?php foreach ($query $search_row) { ?> <?php foreach($checksearch $s) { ?> <?php $box = 0; if($search_row->searchid == $s->idsearch){ $box = 1; } ?> <form method="post" id="the-dash"> <li style="padding-left: 10px;"> <input type="checkbox" id="searches" class="searchid" onclick="getsearchid()" value="<?php echo $search_row->searchid; ?>" name="searchname" <?php echo ($box == 1 ? 'checked' : ''); ?>> <span id="searchname" style="color: #fff; "><?php echo $search_row->searchname; ?> <?php echo '<br>'; ?><span> </li> </form> <?php } ?> <?php } ?> </div> </ul> </li> </ul> </li>
try this
in controller, store id in array
$idsearchs = array(); foreach($checksearch $s) { $idsearchs[] = $s->idsearch; }
in view
<?php foreach ($query $search_row) { $box = in_array($search_row->searchid, $idsearchs) ? 1 : 0; ?> <li style="padding-left: 10px;"> <form method="post" id="the-dash"> <input type="checkbox" id="searches" class="searchid" onclick="getsearchid()" value="<?php echo $search_row->searchid; ?>" name="searchname" <?php echo ($box == 1) ? 'checked="checked"' : ''; ?>> <span id="searchname" style="color: #fff; "><?php echo $search_row->searchname; ?> <?php echo '<br>'; ?><span> </form> </li> <?php } ?>
you have done foreach $query , in side foreach $checksearch, there getting duplicate checkbox.
Comments
Post a Comment