Hi to all
I'm stuck in trying to solve this problem for a days. I even give up for a while, and since i'm a PHP newbie, i need help.
This is my problem: I have a query that selects all appropriate record in a table 'hotels' and then for each hotel looks for booked room of certain type in table 'booked_rooms' and all of that for certain period. So first i'm taking out all hotel_ids from 'hotel_table', based on the location provided from the search form, and for each hotel_id i loop through the 'booked_rooms' table.
Here's the code:
if(isset($_GET['book'])){
$sql=mysql_query("SELECT hotel_id FROM 'hotels' WHERE city='$city") or die(mysql_error());
while($row=mysql_fetch_array($sql)){
$sql_2=mysql_query("SELECT * FROM `booked_rooms` WHERE hotel_id='$hotel_id'
AND arrival_date BETWEEN '$arrival_date' AND '$departure_date'
OR departure_date BETWEEN '$arrival_date' AND '$departure_date'")
or die(mysql_error());
}
while($row_2=mysql_fetch_array($sql_2)){
print_r($row_2);
}
}
// $city, $arrival_date and $departure date are values retrieved from the search form
The problem is that i get a loop through 'hotel' table and get all the hotel_ids appropriate to the location, but got nothing with printing the $row_2 array. I tried using JOINS in the SQL, 'foreach' loop, but no luck as well. I know it's a trivial questions, but i'm still learning, so any tip is highly welcomed. Thanks in advance.