Jump to content

complicated mySQL query


ambrennan

Recommended Posts

Hi all

I am trying to write a query which will search the database for whatever rooms are available on the dates selected (arrival and departure ) which involes querying different tables. I'm new to php and mysql and really struggling with this - The code below is my feeble attempt - Can you help
$query = "SELECT room_number, room_description FROM room_desc_t,
WHERE
room_type = $RoomType, room_smoking = $SmokingYesNo, AND
room_number NOT IN
SELECT res_room_number from reservations_t " WHERE
res_arrival_date <= $arrivalday, res_depart_date > $departuredate
SELECT res_room_number from reservations_t WHERE res_arrival_date >= $arrivalday AND res_arrival_date < $departuredate"
$result=mysql_query ($query) or die ("Unable to execute query: ".mysql_error()); //(mysql_error());
Link to comment
Share on other sites

Guest footballkid4
You can try this:
[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] * [color=green]FROM[/color] [color=orange]`room_desc_t`[/color] t [color=green]LEFT[/color] [color=green]JOIN[/color] `reservations_t` r [color=green]WHERE[/color] t.room_type[color=orange]=[/color][color=red]'{$RoomType}'[/color] [color=blue]AND[/color] room_smoking[color=orange]=[/color][color=red]'{$SmokingYesNo}'[/color] [color=blue]AND[/color] r.res_arrival_date [color=orange]>[/color][color=orange]=[/color] [color=red]'{$Arrival}'[/color] [color=blue]AND[/color] r.res_departure_date [color=orange]<[/color] [color=red]'{$Departure}'[/color] [!--sql2--][/div][!--sql3--]

That should work, but it's untested and not guaranteed.
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.