[Solved] How to retrieve checkbox value from database in php?


        # Please Try again below code.. #


        <tr><td valign="top">Sebab Kekosongan</td><td>
                <?php 
                    $keranaS = array('retire', 'death', 'change', 'promote', 'others');
                    //echo '<pre>'; print_r($keranaS); exit;
                    if(!empty($keranaS))
                    {
                        foreach ($keranaS as $myKerana)
                        {
                            $checked = (in_array($myKerana, $keranaS)) ? 'checked="checked"' : ''; ?>

                           <input type="checkbox" name="kerana[]" value="<?php echo $myKerana; ?>" <?php echo $checked; ?>> <?php echo $myKerana;?>
                  <?php } ?>
                  </td>
            <?php   } ?>

            </tr>



    # Please try again below dynamic through checkbox checked.  


<tr><td valign="top">Sebab Kekosongan</td><td>
    <?php 
        $keranaS = array('retire', 'death', 'change', 'promote', 'others');

        //$kerana_data data databse though fetch
        $kerana_data = array('retire', 'change', 'others');

        if(!empty($keranaS))
        {
            $i = 0;
            foreach ($keranaS as $myKerana)
            { 
                if(in_array($myKerana, $kerana_data)){
                    $checked = (in_array($myKerana, $kerana_data)) ? 'checked="checked"' : ''; ?>
                    <input type="checkbox" name="kerana[]" value="<?php echo $myKerana; ?>" <?php echo $checked; ?>> <?php echo $myKerana;?>
                <?php }else{?>
                    <input type="checkbox" name="kerana[]" value="<?php echo $myKerana; ?>"> <?php echo $myKerana;?>
                <?php }?> 
      <?php $i++;
            } ?>
      </td>
<?php   } ?>
</tr>

4

solved How to retrieve checkbox value from database in php?