我已经搜索过这个问题,但找不到与此类似的内容。这是我的代码:
$serial = "19002817";
$start = "1443597360";
$end = "1443600000";
这是我的MySQL查询:
SELECT * FROM trips WHERE serial = '$serial' AND start_date >= '$start' AND end_date <= '$end';
然后在PHP中我收到以下错误:
查询错误,您的SQL语法中有错误;检查与您的MySQL服务器版本对应的手册,以便在''1443597360'AND_date&lt;附近使用正确的语法。第1行'1443600000'
现在我注意到它与>
和<
符号有关。如果我删除它们,那么一切都很完美。但我以前从未遇到过这个问题。
以下是我的完整代码
<?php
set_time_limit(0);
require_once("includes/DBC.php");
function distance($lat1, $lon1, $lat2, $lon2)
{
$theta = $lon1 - $lon2;
$dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
$dist = acos($dist);
$dist = rad2deg($dist);
$miles = $dist * 60 * 1.1515;
return round($miles * 1.609344, 2);
}
$serial = "19002817";
$start = "1443597360";
$end = "1443600000";
//Have tried
//$start = 1443597360;
//$end = 1443600000;
//Have tried
//$start = (int) "1443597360";
//$end = (int) "1443600000";
$Tdist = 0;
$trips = DBC::dbsql("SELECT * FROM trips WHERE serial = $serial AND start_date >= $start AND end_date <= $end;") or die(DBC::printErrors());
//Have tried
//$trips = DBC::dbsql("SELECT * FROM trips WHERE serial = ".$serial." AND start_date >= ".$start." AND end_date <= ".$end.";") or die(DBC::printErrors());
while($getTrips = DBC::dbfetch($trips))
{
$start_date = $getTripss['start_date'];
$end_date = $getTripss['end_date'];
$cor = DBC::dbsql("SELECT lat, lng FROM z_$serial WHERE datelogged BETWEEN '$start_date' AND '$end_date';");
while($getCor = DBC::dbfetch($cor))
{
$cor_lat = $getCor['lat'];
$cor_lng = $getCor['lng'];
if(!empty($first_lat) && !empty($first_lng))
{
$dist = distance($lat, $lng, $first_lat, $first_lng);
$Tdist += $dist;
}
$first_lat = $cor_lat;
$first_lng = $cor_lng;
}
print "Distance = $Tdist<br />";
}
?>