I have a table made up of a number of columns, id, room_id, property_id, and date.
The property_id could be a category with different room_id being subcategory.
An additional variable is the number of dyas, eg.2 .The date is stored as a timestamp, so if two nigths are selected along with a start date two timestamps are generated.
Im trying to write a php script that will:
- select room_id euqal to or within the timestamps.
- if the number of room_id's found matches the number nights, to then
- display the room_id in groups under the corresponding property_id
if there are no rooms that match then there is no need to display the property_id (category).
So far this is the best i could do (keep in mind im new to php!)
$query = "SELECT DISTINCT property_id FROM availability WHERE status='1' in (SELECT property_id FROM properties WHERE city='".$city."' AND supplier_type='".$property_type."') AND property_id=property_id AND date >= '".$checkin."' AND date <= '".$checkout."'";
$result = mysql_query($query) or die (mysql_error());
while ($row=mysql_fetch_assoc($result)){
$sql = "SELECT DISTINCT property_id FROM availability WHERE room_id='".$row['room_id']."'";
$res = mysql_query($sql) or die (mysql_error());
while($row2 = mysql_fetch_assoc($res)){
echo "".$row2['property_id']."<br/>";
$sql3="SELECT room_id FROM availability WHERE room_id='".$row2['room_id']."'";
$res3=mysql_query($sql3) or die (mysql_error());
if(mysql_num_rows($res3)>=$days){
$sql4="SELECT DISTINCT property_id FROM availability WHERE room_id='".$row2['room_id']."'";
$res4=mysql_query($sql4) or die (mysql_error());
while($row4=mysql_fetch_array($res4)){
echo "".$row4['property_id']."";
echo "<br/>";
#$sql5 = "SELECT * FROM availability WHERE room_id='".$row4['room_id']."'";
$res5 = mysql_query($sql5) or die(mysql_error());
$row5 = mysql_fetch_assoc($res5);
echo "".$row5['id']."";
}
}
}
}
Im guesing i should really be using a foreach looop or for loop to loop through my results but keep coming up with errors.