<?php
$hostname = "localhost";
$db_user = "root";
$db_password = "";
$database = "rentcar";
$db_table = "reservation";
$db = mysql_connect($hostname, $db_user, $db_password);
mysql_select_db($database,$db);
$date1 = $_POST['datepicker1'];
$date2 = $_POST['datepicker2'];
$start_date = strtotime($date1);
$end_date = strtotime($date2);
$query = mysql_query("SELECT * FROM reservation WHERE ('pudate'>".$start_date." AND
'dodate'<".$end_date.") OR ('pudate'<".$start_date." AND 'dodate'>".$end_date." ) OR
('pudate'<".$end_date." AND 'dodate'>".$end_date.") OR ('pudate'<".$start_date." AND
'dodate'>".$start_date." )");
$result = mysql_query($query);
if ($result)
{
echo "vehicle is available";
}
else
{
echo "vehicle is not available";
}
?>
pudate 和 dodate 是数据库中的日期。当我尝试运行时,它总是向我显示输出,因为车辆不可用。我正在运行查询以检查这两天之间汽车是否已经被预订,如果汽车已经被预订,它会说汽车不可用,但无论我如何尝试运行查询,它总是给我相同的结果。