<?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是数据库中的日期。
当我尝试运行时,始终向我显示输出,因为车辆不可用。我正在运行查询st,检查这两天之间是否已经预订了汽车(如果已经预订了汽车),它将说汽车不可用,但是无论我如何尝试运行查询,它总是会给我相同的结果。

最佳答案

您未能获得查询的实际结果。实际上,您两次调用mysql_query()(返回一个句柄)。在您的情况下,请使用mysql_num_rows()获取行数,该行数将告诉您车辆是否可用。

09-27 02:55