6pandn21 Posted March 30, 2010 Share Posted March 30, 2010 Hello guys, I am trying to make a very simple booking system. The booking will be either for the current or the next year only. There are three fields; number of person, type of meal and date. In any particualr day and meal, the number of person can't exceed 100. When the user enters a date, number of people and meal type, the bookingcheck script should check if the booking is available. If it is available; it will allow the user to make a booking for that day and meal type. If there was no booking placed on that day, the script should insert the booking details. My problem is in the logic details, I am being unable to lay out the logic for this. If anyone could clarify, I would be grateful. Thank you. 6pand21 <?php $a = mysql_real_escape_string ($_POST['guest_number']); $b = mysql_real_escape_string ($_POST['date']); $c = mysql_real_escape_string ($_POST['food_type']); $exploded = explode("/", $b); $d = $exploded[0]; $e = $exploded[1]; $f = $exploded[2]; $year= date ("Y"); $nextyear= $year + 1; if (($f != $year) and ($f != $nextyear)) { echo"cannot book for this year"; } else { $result=mysql_query("SELECT * FROM booking WHERE year ='$f' AND food_type ='$c'"); while ($row= mysql_fetch_array($result)) { $guest = $row['guest_number'] + $a; if ($guest > 100) { //number of guest error } else { // continue with the booking } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/196933-logic-for-a-very-simple-booking-script/ Share on other sites More sharing options...
joel24 Posted March 30, 2010 Share Posted March 30, 2010 what is "$guest = $row['guest_number'] + $a" for? Its going to add the amount of the current table to every other table. If you're trying to add up the total amount of guests for that day you should use something like $query = "SELECT SUM(guest_number) AS total_bookings FROM booking WHERE year = $f" //you'll have to add in the code to check the date, i.e. where booking_date = $b Then you'll be able to use $result = mysql_fetch_array($query) $guest_numbers = $result['total_bookings'] Quote Link to comment https://forums.phpfreaks.com/topic/196933-logic-for-a-very-simple-booking-script/#findComment-1033894 Share on other sites More sharing options...
6pandn21 Posted March 30, 2010 Author Share Posted March 30, 2010 what is "$guest = $row['guest_number'] + $a" for? Its going to add the amount of the current table to every other table. If you're trying to add up the total amount of guests for that day you should use something like $query = "SELECT SUM(guest_number) AS total_bookings FROM booking WHERE year = $f" //you'll have to add in the code to check the date, i.e. where booking_date = $b Then you'll be able to use $result = mysql_fetch_array($query) $guest_numbers = $result['total_bookings'] First of all thank you for your suggestion. The idea behind $guest was to get the input guest amount by the user and add it up with current bookings if there were any on that day. For example an user enters 10 people for 30/11/2010. The script will get that 10 people and check if there is enough room for that day. So for that, it will take the 10 people and add it with the already booked people for that day. I will try to implement your suggestion and see what happens. Quote Link to comment https://forums.phpfreaks.com/topic/196933-logic-for-a-very-simple-booking-script/#findComment-1034088 Share on other sites More sharing options...
ignace Posted March 30, 2010 Share Posted March 30, 2010 Your developing an application that is harder then you might think for example the restaurant may only have tables of four so that becomes a problem when someone reserves for 1 person or 3 persons where your application would indicate that there is a seat available but no table.. Quote Link to comment https://forums.phpfreaks.com/topic/196933-logic-for-a-very-simple-booking-script/#findComment-1034101 Share on other sites More sharing options...
6pandn21 Posted March 30, 2010 Author Share Posted March 30, 2010 Your developing an application that is harder then you might think for example the restaurant may only have tables of four so that becomes a problem when someone reserves for 1 person or 3 persons where your application would indicate that there is a seat available but no table.. Yes I am aware of what you said but I am just trying to show a very basic demonstration that something like this can be achieved with PHP. A full fledged application will be completely something else. Quote Link to comment https://forums.phpfreaks.com/topic/196933-logic-for-a-very-simple-booking-script/#findComment-1034393 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.