$sql = "SELECT * FROM borrow WHERE toolid = '".$toolid."' AND ((starttime BETWEEN '".$starttime."' AND '".$endtime."') OR (endtime BETWEEN '".$starttime."' AND '".$endtime."')) AND ((starttime BETWEEN '".$starttime."' AND '".$endtime."') OR (endtime BETWEEN '".$starttime."' AND '".$endtime."')) ";
$qry = mysql_query($sql) or die(mysql_error());
if($row = mysql_fetch_array($qry))
{
echo "อุปกรณ์นี้มีผู้ใช้งานแล้ว!";
} else {
echo "อุปกรณ์นี้สามารถยืมได้";
}
$sql = "SELECT * FROM borrow WHERE toolid = '".$toolid."' AND ((startdate BETWEEN '".$startdate."' AND '".$enddate."') OR (enddate BETWEEN '".$startdate."' AND '".$enddate."')) AND ((starttime BETWEEN '".$starttime."' AND '".$endtime."') OR (endtime BETWEEN '".$starttime."' AND '".$endtime."') OR ('".$starttime."' BETWEEN starttime AND endtime) OR ('".$endtime."' BETWEEN starttime AND endtime ))";
$qry = mysql_query($sql) or die(mysql_error());
if($row = mysql_fetch_array($qry))
{
echo "อุปกรณ์นี้มีผู้ใช้งานแล้ว!";
} else {
echo "อุปกรณ์นี้สามารถยืมได้";
}