codeigniter模型中的错误较少

时间:2014-08-03 06:43:32

标签: php codeigniter

function get_nearby($lat, $long, $option, $top, $range)
{

    if($option == "km")
        $this->db->select("*, ROUND(((acos(sin((".$lat." * pi()/180)) * sin((markers_lat*pi()/180))+cos((".$lat." * pi()/180)) * cos((markers_lat*pi()/180)) * cos(((".$long." - markers_lng) *pi()/180))))*180/pi())*60*1.1515*1.609344) as distance");
    else
        $this->db->select("*, ROUND(((acos(sin((".$lat." * pi()/180)) * sin((markers_lat*pi()/180))+cos((".$lat." * pi()/180)) * cos((markers_lat*pi()/180)) * cos(((".$long." - markers_lng)* pi()/180))))*180/pi())*60*1.1515) as distance");

    $this->db->from('markers');
    $having='distance <='+$range;
    // $this->db->having('distance <' => $range);
    $test =20;
    $this->db->having('distance <=' => $test);
    $this->db->order_by('distance', 'asc');
     $this->db->limit($top);
    $query = $this->db->get();
    $result = $query->result_array();

    return $result;
}

代码在第$this->db->having('distance <=' => $test);行有一些错误 有人可以帮我解决这个问题,拜托!

1 个答案:

答案 0 :(得分:2)

你需要使用 $this->db->having('distance <=' . $test);

而不是$this->db->having('distance <=' => $test);

您使用=>代替.