ambrennan Posted April 4, 2006 Share Posted April 4, 2006 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 " WHEREres_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 https://forums.phpfreaks.com/topic/6531-complicated-mysql-query/ Share on other sites More sharing options...
Guest footballkid4 Posted April 4, 2006 Share Posted April 4, 2006 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 https://forums.phpfreaks.com/topic/6531-complicated-mysql-query/#findComment-23711 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.