jeudi 24 octobre 2019

Disable checkbox if the value is already in databse

I am having trouble disabling checkbox if the value are already in db.

I have tablename staff_availability and it has column from the datatype is time. I have multiple values for from (e.g. 09:00:00, 10:00:00 and so on...) I tried this but it disabled all the checkbox. Here is my code:

include 'dbconfig.php';
$upload_dir = 'uploads/';
 $id = $_SESSION['stfid'];
$sql="SELECT * FROM staff_availability  WHERE stfid = '$id'";
$result = mysqli_query($conn,$sql);
if (mysqli_num_rows($result)>0) {
while($row = mysqli_fetch_array($result)) {
$timelists[] = $row['fro'];
}
}
mysqli_close($conn);
?>
                                            <div class="checkbox checkbox-success checkbox-info">
                                                    <input id="checkbox-15" type="checkbox" name="timelist[]"value="09:00:00" <?php echo (in_array("09:00:00", $timelists)?"disabled='disabled'":"") ?>>
                                                    <label for="checkbox-15">
                                                        09:00 AM - 10:00 AM 
                                                    </label>
                                            </div>
                                            <div class="checkbox checkbox-success checkbox-info">
                                                    <input id="checkbox-15" type="checkbox" name="timelist[]"value="10:00:00" <?php echo (in_array("10:00:00", $timelists)?"disabled='disabled'":"") ?>>
                                                    <label for="checkbox-15">
                                                        10:00 AM - 11:00 AM
                                                    </label>
                                            </div>
                                            <div class="checkbox checkbox-success checkbox-info">
                                                    <input id="checkbox-15" type="checkbox" name="timelist[]"value="11:00:00" <?php echo (in_array("11:00:00", $timelists)?"disabled='disabled'":"") ?>>
                                                    <label for="checkbox-15">
                                                        11:00 AM - 12:00 PM
                                                    </label>
                                            </div>



Aucun commentaire:

Enregistrer un commentaire