Jump to content

Msql Php Booking


S34N

Recommended Posts

Please some1 help me with this code.

 

i've tried soo many times to retrieve the rooms that are not booked. if no rooms have been booked for a specified period match with the user input, then the room is available for booking. and now my PDO Mysql code is spinning in my head...

 

 

 

<?php

/**
* @author S34N
* @copyright 2012
*/

class Connection
{	
Public function dbConnect()
{
	return new PDO("mysql:host=localhost; dbname=waterfall", "root", "6354");
}
}

class Date_a
{
private $db;

public function __construct()
{
	$this->db = new Connection();
	$this->db = $this->db->dbConnect();
}

public function Query($arr, $dep)
{
	try
	{
		if (!empty($arr) && !empty($dep))																							   //Check_In between booked dates	 Check_out							   User Prompted arrival date			   User Departure Date
		{
			$st = $this->db->prepare("SELECT `schedule`.`Check_In` , `schedule`.`RoomNo` , `schedule`.`Check_Out` FROM schedule WHERE (Check_In BETWEEN ? AND ? || Check_Out BETWEEN ? AND ?)");
			$st->bindParam(1, $arr);
			$st->bindParam(2, $dep);
			$st->bindParam(3, $arr);		//("SELECT `schedule`.`Check_In` , `schedule`.`RoomNo` , `schedule`.`Check_Out` FROM schedule WHERE ((Check_In >= ?) AND (Check_Out <= ?))");
			$st->bindParam(4, $dep);		//("SELECT `schedule`.`Check_In` , `schedule`.`RoomNo` , `schedule`.`Check_Out` FROM schedule WHERE ((? NOT BETWEEN Check_In AND Check_Out) AND (? NOT BETWEEN Check_In AND Check_Out))");		
			$st->execute();				 //("SELECT `schedule`.`Check_In` , `schedule`.`RoomNo` , `schedule`.`Check_Out` FROM schedule WHERE ((Check_In BETWEEN ? AND ?) || (Check_Out BETWEEN ? AND ?) || (? BETWEEN Check_In AND Check_Out) || (? BETWEEN Check_In AND Check_Out))");

			if($st->rowCount() >= 1)	
			{
				$num = $st->rowCount();
				echo $num;
				echo "Booked !";
			}
			else
			{
				$status = "Available";
				$num = 0;
				echo $status;
			}
		}
		else
		{
			echo "Empty input.";
		}
		$this->db = null;   //Close Database Connection
	}
	catch (PDOException $e)
	{
		echo $e->getMessage(); //Returns error message.
	}
}
}
?>

Edited by fenway
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.