mercredi 22 juillet 2020

Duplicate checkbox remove in php

I have two tables bookings and packages. Checked checkbox are retrieve from booking table is working perfectly. But I need also didn't checked check boxes from packages table. but problem is checked checkbox value display again.

Here is the display screenshot

<?php

$get_pro = "select * from booking";
$result = mysqli_query($con, $get_pro);

$book_packages = $row_pro['Book_Packages'];
$book_packages = substr(trim($book_packages) , 0, -1);
$split_pkg = (explode(",", $book_packages));
if (!empty($split_pkg)) {
    foreach ($split_pkg as $book_pkg) {
        $checked = (in_array($book_pkg, $split_pkg)) ? 'checked="checked"' : '';
?>
                        
        <input type="checkbox" name="pkg_list_name[]" value="<?php echo $book_pkg; ?>" size="17" <?php echo $checked; ?>> <?php echo $book_pkg; ?> <br>
<?php
    }
}

$get_pros = "select * from package";
$results = mysqli_query($con, $get_pros);

while ($row_pros = mysqli_fetch_array($results)) {
    $package_name = $row_pros['Pkg_Name'];

    if ($package_name != $split_pkg) {
        echo "<input type='checkbox' data-parsley-required='true' value='$package_name' data-parsley-trigger='click' id='checkbox1' name='pkg_list_name[]'>&nbsp;&nbsp;
            <label>$package_name</label><br> ";
    } else {

    }
}
?>



Aucun commentaire:

Enregistrer un commentaire