Room avaibility

how to do php and mysql

ID name ch_date out_date no_of_room
1 rohit 2011-02-21 2011-02-25 2

if i have 10 room and user booked 2 room then query so after fetch only 8 room available by checking date checkdate and check out date please assist me as possible as

Hi there heres a rough function which you could try and use its


function checkRooms($inDate,$OutDate,$CDate)
{
	//
	include("dbconnect.php");
	$cQuery="select * from rooms WHERE ch_date='$date' AND out_date='$OutDate'";
	$rs=mysqli_query($con,$cQuery);
	if(!$rs)
	{
		echo "Error".mysqli_error($con);
	}
	else
	{
		//if there is no error display
		$count=$rs->num_rows;
		if($count>0)
		{
			
			while($data=$rs->fetch_assoc())
			{
				$today = date('Y-m-D');
				if($today = $CDay)
				{
					//
					echo "Room is Booked";
					//
				}
				else
				{
					//
					echo "Room is aviable";
					//
				}
			}
		}
		//	
	}

	//	
}
$inDate = "2011-02-21";
$OutDate = "2011-02-25";
$CDate = "2011-02-25";
checkRooms($inDate,$OutDate,$CDate);

That should get you started if you got any questions feel free to pm me or reply here

i understand that code but i want to know one thing one table is enough or we have to create another table for set number of room
see here
i have only 10 room
and how to set in variable 10 room or i have to set 10 room in database please
help me as posible as
i m looking search room avaibility

<?php 

$dbhost = 'localhost';
$dbuser = 'root';
$conn = mysql_connect($dbname,$dbuser)or die("error in connection");
$dbname = 'search';

    mysql_select_db($dbname);
    
    $ch_date = $_POST['chdate'];
    $ou_date = $_POST['oudate'];
    $no_room = $_POST['room'];
    
    
    
    
function checkRooms($inDate,$OutDate,$CDate)
{
   
    $cQuery="select * from check WHERE ch_date ='$date' AND ou_date='$OutDate'";
    $rs=mysqli_query($cQuery);
    
   if
   {
        
       // $count=$rs->num_rows;
        if($count>0)
        {
            
            while($data=$rs->fetch_assoc())
            {
                $today = date('Y-m-D');
                if($today = $CDay)
                {
                    //
                    echo "Room is Booked";
                    //
                }
                else
                {
                    //
                    echo "Room is aviable";
                    //
                }
            }
        }
        //    
    }

    //    
}
/*$inDate = "2011-02-21";
$OutDate = "2011-02-25";
$CDate = "2011-02-25";
checkRooms($inDate,$OutDate,$CDate);  */

hello sir code not work
so please help me i have try so much but why not work i m geting confuse

What is the table structure for the table(s) concerned?

for search room avaibility

i have one table it name booking
table colum have

id, name, check_in_date, check_out_date, No_Of_room

we have 10 room

above have booking prosess

and below have search part

but how to set 10 room in No_Of_room coloum in database
i m confuse
but table have one booking

but i also cunfuse i have to use one table or two table
but i m using one table it name booking

search part have :- id, check_in_date, check_out_date, No_Of_room

if i book two room 2011/02/25 to 2011/02/27 in that day user see only 8 room avalable dateformat :- yyyyy/mm/dd

please assist me

Try this code make sure you put your mysql connection into the function heres new code

Make sure you set room to name of your booking table and change the mysqli tags to mysql and it should work if not post errors back here.


function checkRooms($room)
{
   
   $cQuery="select * from room WHERE No_Of_room='$room'";
   $rs=mysqli_query($cQuery);
   if(!$rs)
   {
	   	echo "Error".mysqli_error($con);
   }
   else
   {
	    $count=$rs->num_rows;
        if($count>0)
        {
            
            while($data=$rs->fetch_assoc())
            {
                $status = $data['status'];
                if($status = "1")
                {
                    //
                    echo "Room is Booked";
                    //
                }
                else
                {
                    //
                    echo "Room is aviable";
                    //
                }
            }
        }
        //    
    }   
}
/*
$room = "20";
checkRooms($room);  */

That should help you, you will require the mysqli connection so u can just change mysqli to mysql make sure in your booking function.

you will also need to add a line of code to check each room’s status which i can suggest having a seperate mysql table like this


CREATE TABLE IF NOT EXISTS `room` (
  `rid` int(11) NOT NULL,
  `No_Of_room` int(11) NOT NULL,
  `status` int(11) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

Thats what i can suggest

that would be better way to do it to keep a record which rooms is taken so list all rooms in your rooms tables
having them start off with status of 0 being aviable to book if they are status 1 then it means if is taken and then of course add the information into booking table for all booked rooms and you can gather other information eg who the information is booked by when they booked when they are due to checkout and to checkIn.

I Hope this helps