dsfjnxjlbqv9812 2015-10-23 11:06
浏览 26

MySQL查询在PHPMyAdmin中运行,但在PHP中出错

I have searched this question all over but could not find anything similar to this. Here is my code:

$serial = "19002817";
$start = "1443597360";
$end = "1443600000";

And here is my MySQL query:

SELECT * FROM trips WHERE serial = '$serial' AND start_date >= '$start' AND end_date <= '$end';

but then in PHP I get the following error:

Query error, You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''1443597360' AND end_date < '1443600000'' at line 1

Now I have noticed that it has to do with the > and < signs. If I remove them, then all works perfect. But I have never had this problem before.

Below is my full code

<?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 />";
    }
?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 2024-五一综合模拟赛
    • ¥15 下图接收小电路,谁知道原理
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
    • ¥15 ETLCloud 处理json多层级问题
    • ¥15 matlab中使用gurobi时报错
    • ¥15 这个主板怎么能扩出一两个sata口
    • ¥15 不是,这到底错哪儿了😭