Jump to content


complicated mySQL query

  • Please log in to reply
1 reply to this topic

#1 ambrennan

  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 04 April 2006 - 01:14 AM

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,
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());

#2 Guest_footballkid4_*

  • Guests

Posted 04 April 2006 - 03:21 AM

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

That should work, but it's untested and not guaranteed.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users