Question

<?php
$i = 0;
foreach($prj_data as $prj_pop) {?>
    <input type="checkbox" class="checkbox_project" value="<?php echo  $prj_pop->name;?>"
<?php
if($temp_imp[$i]==$prj_pop->name) echo 'checked="true"'; ?>>
<?php //echo  $prj_pop->name; ?>
    <br><br>
<?php
    $i++;
}?>
  1. Foreach is used for showing the dynamic checkboxes
  2. Total checkboxes are 4
  3. $temp_imp[$i] is getting the values

    School Children    Admission Fee
    
  4. $prj_pop->name is also having values

    School Children    Admission Fee
    
  5. Actual output to be checkbox to be checked while editing is 2 checkboxes since $i is incremented all the checkboxes are selected. Pls help me with this. The above is my way

Was it helpful?

Solution

<?PHP 
    if($events){
      foreach($events as $event){ ?>
      <tr>
            <?php
              if($event->ev_ap==1){ $checked="checked";}else{$checked = "";}
             ?>
        <td class="tab_content">
<input type="checkbox" value="<?=$event->event_id?>" <?=$checked?> name="app[]" id="app[]">
</td>
</tr>

OTHER TIPS

don't use checked="true", but use either just the word checked, or checked="checked"

and as u_mulder said, your comparing 1=1, or always true values, compare against a actual dynamic value.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top