我的mysql数据库是:
BOOKING_ID, FROM_DATE, TO_DATE,
R1,R2,R3,R4,R5,R6,R7,R8,R9,R10,R11,R12,R13,R14,R15,R16,R17
其中 R1=room1...R17=room17,如果 room1 已预订,则 R1 将设置为 1。
下面是我当前工作的 sql 查询,我以前从未学习过 sql,我需要帮助以获得更好的 sql 查询!
for($room=1;$room<=$total_room;$room++)
{
$result = mysql_query("
SELECT COUNT(`BOOKING_ID`) AS num
FROM $search_for_db_table
WHERE ( (FROM_DATE <= $search_to_date AND TO_DATE >= $search_to_date )
OR (FROM_DATE <= $search_from_date AND TO_DATE >= $search_from_date)
OR (FROM_DATE >= $search_from_date AND TO_DATE <= $search_to_date )
)
AND R$room=1
") or die(mysql_error());
$row = mysql_fetch_assoc($result);
$numUsers[$room] = $row['num'];
}
//$numUsers[$room]=="0" means room available for booking...