简体   繁体   English

此地图查询有什么问题? 我收到以下错误

[英]What is wrong with this map query? I am getting the below error

Model: 模型:

function mapdisplay($lat1,$lng1,$cid2)
{
   $this->db->select("cname,frmid,frno,(6371 * acos( cos( radians('$lat1') ) * cos( radians(lat) ) * cos( radians(longi) - radians('$lng1') ) + sin( radians('$lat1') ) * sin( radians(lat) ) ) )AS distance)");
   $this->db->from("tablefir");
   $this->db->where("frmid NOT IN ($cid2)");
   $this->db->having("distance <= 1");
   $this->db->order_by("distance LIMIT 20");
   $query = $this->db->get();
   return $query->result();
}

Error Number: 1064 错误号:1064

You have an error in your SQL syntax; 您的SQL语法有误; check the manual that corresponds to your MariaDB server version for the right syntax to use near ') FROM ( tablefir ) WHERE frmid NOT IN (5,10) HAVING distance <= 1 ORDER BY ' at line 1 检查与您的MariaDB服务器版本相对应的手册以获取正确的语法,以在')FROM( tablefir )WHERE frmid NOT IN(5,10)HAVING distance <= 1 ORDER BY'的第1行附近使用

SELECT `crimehead`
    ,`frmid`
    ,`firno`
    ,(6371 * acos(cos(radians('15.859151')) * cos(radians(lat)) 
           * cos(radians(longi) - radians('74.513124')) + sin(radians('15.859151')) 
           * sin(radians(lat)))) AS distance )
FROM (`tablefir`)
WHERE `frmid` NOT IN (
        5
        ,10
        )
HAVING `distance` <= 1
ORDER BY `distance` LIMIT 20

You given one extra closing braces, change your query with this 您给了一个额外的右括号,用这个来改变您的查询

SELECT crimehead
    ,frmid
    ,firno
    ,(6371 * acos(cos(radians('15.859151')) * cos(radians(lat)) 
           * cos(radians(longi) - radians('74.513124')) + sin(radians('15.859151')) 
           * sin(radians(lat)))) AS distance
FROM (tablefir)
WHERE frmid NOT IN (
        5
        ,10
        )
HAVING distance <= 1
ORDER BY distance LIMIT 20;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM