1

why this is not working? I want this check the checkbox if pro_cat variable is greater than or equal one else unchecked the checkbox

<?php
  $checked="";
  if($pro_cat>=1){
    $checked="checked";
  }

  echo"
    <tr>        
       <td ><br>Day<hr>Night</td>
       <td>
         <label class='container'>
           <input type='checkbox' checked='$checked'>
           <span class='checkmark'></span>
         </label>";

?>
Sofyan Thayf
  • 1,322
  • 2
  • 14
  • 26

1 Answers1

1

Your condition on false becomes like this: <input type='checkbox' checked=''> which is always true for making checked to checkbox. So change like this:

<?php
$checked="";
        if($pro_cat>=1){

            $checked="checked";
        }

        echo"
        <tr>        

                    <td ><br>Day<hr>Night</td>
                    <td>
                    <label class='container'>
                        <input type='checkbox' $checked>
                        <span class='checkmark'></span>
                    </label>";

?>
Ankur Mishra
  • 1,284
  • 1
  • 6
  • 15