= Reser-6ren">
gpt4 book ai didi

php - 如何组合两个单独的 mysql 查询

转载 作者:行者123 更新时间:2023-11-30 22:38:47 25 4
gpt4 key购买 nike

组合这些 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运算符(operator)而不是同时测试 >=<= .

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

关于php - 如何组合两个单独的 mysql 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31662009/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com