13 Replies Latest reply on May 21, 2015 2:13 PM by bregent

    Best way to display availability for booking system

    Max Resnikoff

      Hi,

       

      I currently have a form with a dropdown menu allowing users to select the amount of seats they would like to book.

       

      The field currently reduces from 10 down to 0  in conjunction with how many seats are available.

       

      The problem is that I am adding another variable to the scenario whereby the same field will reduce if the 'event' setting state that only a certain amount of seats can be booked per transaction.

       

      There are 2 variables:

      - $seats_available (Thats how many seats have not yet been booked)

      - $row_prod_detail['seats_per_booking'] (How many seats are allowed per transaction)

       

      I have tried adding an OR statement into the form field, but it returns 1-5 and 1-10 all in the dropdown menu -> resulting in 15 options.

      Here is the form field code:


       

      <label for="quantity"></label>

                            <select name="quantity" id="quantity" class="quantity_dwfield">

                            <option value="-1" selected="selected">Amount of Seats</option>

                            <option value="-1">----------</option>

                                  <?php if($seats_available <=10 || $row_prod_detail['seats_per_booking'] <=10) { ?>

                                  <?php if($seats_available == 0 || $row_prod_detail['seats_per_booking'] == 0) { ?>

                                  <option value="">No Seats Left!</option>

                                  <?php } ?>

                                  <?php if($seats_available == 1 || $row_prod_detail['seats_per_booking']  == 1) { ?>

                                  <option value="1">1</option>

                                  <?php } ?>

                                  <?php if($seats_available == 2 || $row_prod_detail['seats_per_booking'] == 2) { ?>

                                  <option value="1">1</option>

                                  <option value="2">2</option>

                                  <?php } ?>

                                  <?php if($seats_available == 3 || $row_prod_detail['seats_per_booking'] == 3) { ?>

                                  <option value="1">1</option>

                                  <option value="2">2</option>

                                  <option value="3">3</option>

                                  <?php } ?>

                                  <?php if($seats_available == 4 || $row_prod_detail['seats_per_booking'] == 4) { ?>

                                  <option value="1">1</option>

                                  <option value="2">2</option>

                                  <option value="3">3</option>

                                  <option value="4">4</option>

                                  <?php } ?>

                                  <?php if($seats_available == 5 || $row_prod_detail['seats_per_booking'] == 5) { ?>

                                  <option value="1">1</option>

                                  <option value="2">2</option>

                                  <option value="3">3</option>

                                  <option value="4">4</option>

                                  <option value="5">5</option>

                                  <?php } ?>

                                  <?php if($seats_available == 6 || $row_prod_detail['seats_per_booking'] == 6) { ?>

                                  <option value="1">1</option>

                                  <option value="2">2</option>

                                  <option value="3">3</option>

                                  <option value="4">4</option>

                                  <option value="5">5</option>

                                  <option value="6">6</option>

                                  <?php } ?>

                                  <?php if($seats_available == 7 || $row_prod_detail['seats_per_booking'] == 7) { ?>

                                  <option value="1">1</option>

                                  <option value="2">2</option>

                                  <option value="3">3</option>

                                  <option value="4">4</option>

                                  <option value="5">5</option>

                                  <option value="6">6</option>

                                  <option value="7">7</option>

                                  <?php } ?>

                                  <?php if($seats_available == 8 || $row_prod_detail['seats_per_booking'] == 8) { ?>

                                  <option value="1">1</option>

                                  <option value="2">2</option>

                                  <option value="3">3</option>

                                  <option value="4">4</option>

                                  <option value="5">5</option>

                                  <option value="6">6</option>

                                  <option value="7">7</option>

                                  <option value="8">8</option>

                                  <?php } ?>

                                  <?php if($seats_available  == 9 || $row_prod_detail['seats_per_booking'] == 9) { ?>

                                  <option value="1">1</option>

                                  <option value="2">2</option>

                                  <option value="3">3</option>

                                  <option value="4">4</option>

                                  <option value="5">5</option>

                                  <option value="6">6</option>

                                  <option value="7">7</option>

                                  <option value="8">8</option>

                                  <option value="9">9</option>

                                  <?php } ?>

                                  <?php if($seats_available == 10 || $row_prod_detail['seats_per_booking'] == 10) { ?>

                                  <option value="1">1</option>

                                  <option value="2">2</option>

                                  <option value="3">3</option>

                                  <option value="4">4</option>

                                  <option value="5">5</option>

                                  <option value="6">6</option>

                                  <option value="7">7</option>

                                  <option value="8">8</option>

                                  <option value="9">9</option>

                                  <option value="10">10</option>

                                  <?php } ?>

                                  <?php } ?>

                                  <?php if($seats_available > 0 || $row_prod_detail['seats_per_booking'] >10) { ?>

                                  <option value="1">1</option>

                                  <option value="2">2</option>

                                  <option value="3">3</option>

                                  <option value="4">4</option>

                                  <option value="5">5</option>

                                  <option value="6">6</option>

                                  <option value="7">7</option>

                                  <option value="8">8</option>

                                  <option value="9">9</option>

                                  <option value="10">10</option>

                                  <?php } ?>

                                 

                            </select>



      Any help would be very much appreciated!

        • 1. Re: Best way to display availability for booking system
          bregent Most Valuable Participant

          Use a loop to add option values to the dropdown based on the number of available seats. In the loop you can exit when the count = x if the transaction are limited. Simple and 10x less code.

          • 2. Re: Best way to display availability for booking system
            Max Resnikoff Level 1

            I've never actually created a loop in my life! i know; disappointing.

             

            How would i go about doing this? I have seen some tutorials, but none of them address multiple variables (the show something like 0 - 10, but not 0-10 as a default and changing if one of the variable goes below 10)

             

            The loop needs to:

            • show 1-10 IF BOTH $availability AND $seats_per_person are OVER 10
            • Show 1-x IF EITHER $availability OR $seats_per_person are BELOW 10 (Eg. if $seats_per_person is limited to 3, then the loop will go from 1-3. If $availability is 1, then regardless of the $seats_per_person cap (of 3) it will only show 1)

             

            EDIT:

             

            This is what i have got. It seems to work, but am i doing something which i shouldnt? like formatting/organisational wise?

             

            <select name="quantity" id="quantity" class="quantity_dwfield">

            <option value="-1" selected="selected">Amount of Seats</option>

            <option value="-1">----------</option>

                                       

            <?php

              for ($i = 1; ; $i++) {

              ?>

            <option value="$i"><?php echo $i ?></option>

            <?php

              if ($i >= 10) {

              break;

              }

              if ($i >= $row_prod_detail['seats_per_booking']) {

              break;

              }

              if ($i >= $seats_available) {

              break;

              }

              }

              ?>

            </select>

            • 3. Re: Best way to display availability for booking system
              osgood_ Level 8

              You'll surely want to keep this seperate and throw a message if the purchaser has attempted to buy more seats in any one transaction than is allowed?

               

              You can have a field in your database where you can specify how many tickets can be purchased in any one transaction and assign that to a variable - $max_seat_transaction

               

              The rest should be simple  - loop through the seats available as Bregent suggested (see code below)

               

              <?php

              $seats_available = 10;

              $max_seat_transaction = $_POST['quantity'];

              $seat_quantity = $_POST['quantity'];

              ?>

               

              <!DOCTYPE html>

              <html xmlns="http://www.w3.org/1999/xhtml">

              <head>

              <meta charset="UTF-8" />

              <title>Untitled Document</title>

              </head>

               

              <body>

              <?php

              if($max_seat_transaction > 4) {

              echo "Sorry a maximum of 4 tickets can be purchased in any one transaction";

              }

              elseif (isset($seat_quantity)) {

              echo "You have purchased $seat_quantity seats";

              }

               

              ?>

              <form action="" method="post">

              <p>

              <select name="quantity" id="quantity" class="quantity_dwfield">

              <option value="" selected="selected">Amount of Seats</option>

              <?php

              $i = 1;

              while($i <= $seats_available) {

              echo '<option value="'.$i.'">'.$i.'</option>';

              $i++;

              }

              ?>

              </select>

              </p>

              <p>

              <input type="submit" name="submit" value="Purchase Tickets">

              </p>

              </form>

               

              </body>

              </html>

              • 4. Re: Best way to display availability for booking system
                Max Resnikoff Level 1

                So the code that i posted above (The loop), it displays and fully works when selecting it through the form, but it is returning 0 in the database, even though in the drop down menu (with the loop), i selected 3

                • 5. Re: Best way to display availability for booking system
                  osgood_ Level 8

                  Max Resnikoff wrote:

                   

                  So the code that i posted above (The loop), it displays and fully works when selecting it through the form, but it is returning 0 in the database, even though in the drop down menu (with the loop), i selected 3

                  Then the value associated with the <option> tag cant be 3 it must be 0. Have you looked at the source code?

                  • 6. Re: Best way to display availability for booking system
                    Max Resnikoff Level 1

                    Found the issue.

                     

                    I had:

                    ?>

                    <option value="$i"><?php echo $i ?></option>

                    <?php

                     

                    and have now changed it to:

                    echo'<option value="'.$i.'">'.$i.'</option>';

                    • 7. Re: Best way to display availability for booking system
                      Max Resnikoff Level 1

                      Thanks for your help guys! (Again)

                      • 8. Re: Best way to display availability for booking system
                        bregent Most Valuable Participant

                        >You'll surely want to keep this seperate and throw a message if the purchaser

                        >has attempted to buy more seats in any one transaction than is allowed?


                        Osgood, I wouldn't do it that way. Why show a number of seats if you can't purchase them? Just use both conditions to populate the dropdown.


                        <?php

                        $i = 1;

                        while($i <= $seats_available AND $i <=$max_seat_transaction )  {

                        echo '<option value="'.$i.'">'.$i.'</option>';

                        $i++;

                        }

                        • 9. Re: Best way to display availability for booking system
                          osgood_ Level 8

                          bregent wrote:

                           

                          >You'll surely want to keep this seperate and throw a message if the purchaser

                          >has attempted to buy more seats in any one transaction than is allowed?


                          Osgood, I wouldn't do it that way. Why show a number of seats if you can't purchase them? Just use both conditions to populate the dropdown.


                          <?php

                          $i = 1;

                          while($i <= $seats_available AND $i <=$max_seat_transaction )  {

                          echo '<option value="'.$i.'">'.$i.'</option>';

                          $i++;

                          }

                           

                          Yeah, I didnt really fully understand what Max wanted to be honest, was just trying to bowl something over about using a loop and then get my head around what the ultimate goal was.

                           

                          I'm not sure that if there are 10 seats left and only 4 are shown is the best way to go to be honest. The person could presumably buy another block of 4 tickets in an additional transaction but may never know anymore tickets are available if just 4 are shown...........hummm.

                           

                          I dunno what the idea behind limiting the amount of tickets that can be bought in any one transaction is, I'd want to sell them all to whoever is willing to purchase them.

                          • 10. Re: Best way to display availability for booking system
                            Max Resnikoff Level 1

                            The reason as to why they have to be limited is because for these school productions, there are limited seats, and the school doesnt want a family of 15 to go, (because they may restrict other families from having the opportunity to go to one of the productions), so would rather reduce that to 4 or 5 (variable limit).

                             

                            p.s. I know im so bad at explaining things

                            • 11. Re: Best way to display availability for booking system
                              osgood_ Level 8

                              Max Resnikoff wrote:

                               

                              The reason as to why they have to be limited is because for these school productions, there are limited seats, and the school doesnt want a family of 15 to go, (because they may restrict other families from having the opportunity to go to one of the productions), so would rather reduce that to 4 or 5 (variable limit).

                               

                              p.s. I know im so bad at explaining things

                               

                              Nice thinking but what stops Mrs Smith buying four on her credit card and then Mr Smith rocking up and buying another four on his credit card?

                               

                              I like the thought behind it but in 'reality' its not possible.

                               

                              I guess its possible if there is manual intervention and you have someone checking the family address maybe lol

                               

                              Its a school thing so anything is possible I guess.

                              • 12. Re: Best way to display availability for booking system
                                Rob Hecker2 Adobe Community Professional & MVP

                                and the school doesn't want a family of 15 to go

                                 

                                The wisdom of that approach escapes me.

                                • 13. Re: Best way to display availability for booking system
                                  bregent Most Valuable Participant

                                  Right, you can't prevent it.

                                   

                                  @Max, if transactions are limited then I would limit the amount in the dropdown, and also show an alert near the dropdown explaining why it is limited. Some folks will cheat, but others will understand the reasoning.