Linked Questions

Popular Questions

I need to use nested foreach for dependent checkboxes.

    <input type="checkbox"  name="all[]" value="<?php echo $row_bus_details['busid'];?>" >

      $book_side_result = mysqli_query($db,"select * from advt_sides");
   <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'];?>" > <?php echo $book_side_row['advt_side']; ?><br/>
                                          <?php } ?>

I need to loop the selected values of second checkbox if the first checkbox is selected.

I wrote the code like

$i = 0;
           $busid = isset($_POST['all']) ? $_POST['all'] : array();
           foreach ((array)$busid as $item) {

       if(!empty($_POST['bookingside'])) {
            foreach($_POST['bookingside'] as $side) {
                $sql_book_side=mysqli_query($db,"INSERT INTO `advt_book_side`(bus_id,sides_id) VALUES ('$item','$side')");

The result I need is just like the image below

required output

Related Questions