组合这些mysql查询的正确语法是什么?

$reserved = mysql_query("Select * from reservations where $timestamp >= ReservationStart AND $timestamp <= ReservationEnd");




$reserved2 = mysql_query("Select * from reservations where $ReservationEnd >= ReservationStart AND $ReservationEnd <= ReservationEnd");


我希望保留满足这两个条件,但是我对使用mysql很陌生(而且我知道它已经过时了,但是出于我使用它的目的,它比较容易),所以我不确定如何放置这两个在一起。

最佳答案

WHERE子句与AND结合在一起。您也可以使用BETWEEN运算符,而不是同时测试>=<=

$reserved = mysql_query("Select *
    from reservations
    where $timestamp BETWEEN ReservationStart AND ReservationEnd
    AND $ReservationEnd BETWEEN ReservationStart AND ReservationEnd") or die(mysql_error());

10-01 00:59