codeigniter requete获得两个参数

时间:2015-03-10 21:31:32

标签: sql codeigniter api

我想从当前位置(纬度,经度)获取附近的地方

我在我的控制器中制作这个方法

 function etablissement_get(){if(!$this->get('latitude','longitude')){
         $this->response(NULL, 400);
    }
    $data = array('etablissements:',$this->Etablissement_model->get_relation_by_etablissement($this->get('latitude','longitude')));

     if($data)
    {
        $this->response($data, 200);
    }
    else
    {
        $this->response(array('error' => 'Entity could not be found'), 404);
    }}

和我的模型中的这个方法

public function get_relation_by_etablissement($latitude,$longitude)
{
  $this->db->select(' m.ref_relation,m.image,mylocation.latitude as "latitude my location",mylocation.longitude as "longitude my location", near.latitude as "latitude nearby me",near.longitude as "longitude near by me",near.title as "title nearby me",near.actif as"state nearby me",near.adresse as "adresse nearby me",near.rate as"rate nearby me"');
    $this->db->from('relations M');

    $this->db->join('etablissement mylocation', ' m.ref_local=mylocation.id ');
    $this->db->join('etablissement near', ' m.ref_relation=near.id ');

    $this->db->where('mylocation.latitude',$latitude, 'mylocation.longitude',$longitude);



          $query=$this->db->get();
          echo $this->db->last_query();
return $query->result();}

我得到了结果,但有一些警告。当我var_dump我的查询时,参数中只有一个参数(纬度= 55.978456)没有经度。如何使它与两个参数一起使用

2 个答案:

答案 0 :(得分:0)

应该是这样的:

if(!$this->get('latitude') || !$this->get('longitude'))
{
     $this->response(NULL, 400);
}

答案 1 :(得分:-1)

$这 - > DB-化合物其中(' mylocation.latitude',$纬度); $这 - > DB-化合物其中(' mylocation.longitude',$经度);

它会将其视为" SELECT ... FROM ... WHERE mylocation.latitude = $ latitude AND mylocation.longitude = $ longitude"