1

I need to create a bus seat booking system. As you can see from the image below, there are 30 seats with 3 column. Currently after clicking the submit button, my code (can see example code below) will display the seat number that they have chosen. But what I want to add is to display the seat type and price, ok for example (from the image):

  • Left column type of seat is 'single', middle column is 'aisle', and right column is 'window'.
  • 'single' seat is $10 while the others are $5.

So, how do I display the seat number with its type and price in efficient way? (maybe using multidimensional array?). Sorry if my question is not clear enough as I'm still beginner in coding.

bus seat booking system (click here to see the image)

my html (3 seat example):

        <li class="seat">
          <input type="checkbox" name="seatcheckbox[]" value="1" id="1"/>
          <label for="1"></label>
        </li>

        <li class="seat">
          <input type="checkbox" name="seatcheckbox[]" value="2" id="2"/>
          <label for="2"></label>
        </li>

        <li class="seat">
          <input type="checkbox" name="seatcheckbox[]" value="3" id="3"/>
          <label for="3"></label>
        </li>

my php:

if (isset($_POST["submit"]))
{
  if(!empty($_POST["seatcheckbox"]))
  {
    echo 'You have selected the following seats: ';
    foreach($_POST["seatcheckbox"] as $seatcheckbox)
    {
      echo $seatcheckbox . ', ';
    }
  }
  else {
    {
      echo 'Please select at least 1 seat';
    }
  }
}
3
  • You have not included the HTML code for price Commented Nov 17, 2020 at 4:38
  • @NadirLatif I have yet to do it. I mean, I want different price for single seat ($10) and others ($5). How do I assign it and output it corresponding with the user's seat selection? Commented Nov 17, 2020 at 6:34
  • Please include the HTML code Commented Nov 17, 2020 at 11:45

1 Answer 1

1

There are other ways to do it, for simplicity since I haven't seen your HTML implementation you can experiment with this:

<?php
 for( $i = 0; $i <= 30 ; $i++){
      if( ( ($i+3) % 3) == 0){
           echo "single price";
        }else{
           echo "double price";
      }
 }
?>
Sign up to request clarification or add additional context in comments.

1 Comment

this looks promising, I will try it later. Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.