Jump to content

Logic for a very simple booking script


6pandn21

Recommended Posts

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
		}
	}
	}

?>

Link to comment
Share on other sites

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']

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.