I need to use nested foreach for dependent checkboxes.
<input class="bookmain" type="checkbox" id="bus<?php echo $row_bus_details['busid'];?>" name="all[]" onchange="return OptionsSelected(this)" value="<?php echo $row_bus_details['busid'];?>" >
<?php
$book_side_result = mysqli_query($db,"select * from advt_sides");
while($book_side_row=mysqli_fetch_array($book_side_result))
{
?>
<input type="checkbox" name="bookingside[]" value="<?php echo $book_side_row['advt_side_id']; ?>" id="<?php echo $book_side_row['advt_side']; ?><?php echo $row_bus_details['busid'];?>" name="<?php echo $book_side_row['advt_side']; ?>"> <?php echo $book_side_row['advt_side']; ?><br/>
<?php } ?>
$i = 0;
$busid = isset($_POST['all']) ? $_POST['all'] : array();
foreach ((array)$busid as $item) {
if(!empty($_POST['bookingside'])) {
$j = 0;
foreach($_POST['bookingside'] as $side) {
$sql_book_side=mysqli_query($db,"INSERT INTO `advt_book_side`(bus_id,sides_id) VALUES ('$item','$side')");
$j++;
}
$i++;
}
}