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

时间:2017-06-17 06:42:42

标签: php sql

型号:

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();
}
  

错误号码:1064

     

您的SQL语法有错误;检查手册   对应于您的MariaDB服务器版本,以获得正确的语法   靠近')FROM(tablefir)WHERE frmid NOT IN(5,10)HAVING   第1行distance&lt; = 1 ORDER BY'

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

1 个答案:

答案 0 :(得分:2)

你给了一个额外的结束括号,用这个

更改你的查询
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;