2015-08-25 73 views
0

我試圖通過'id'格式id調用數據id id = GE-DIS-001 to JOIN table with笨,「未知列 'GE' 的結果 'where子句' 出了什麼問題?用varchar格式調用mysql數據庫的'id',但在'where子句'中調用未知列'GE'

控制器:

public function detail(){ 

    $id = $this->uri->segment(4); 
    $detail = $this->mcrud->get_detail($id); 

    $data = array(
       'detail'=>$detail, 
       'lihat' =>$this->mcrud->lihat_komentar($id), 
       'isi'  =>'instrument/read_views'); 
    $this->load->view('layout/wrapper', $data); 


    }  

型號:

public function get_detail($id){ 

    $sql = "SELECT * FROM tbdetail 
      JOIN tbkalibrasi ON tbkalibrasi.id = tbdetail.id 
      JOIN tbsupplier ON tbsupplier.namasupplier = tbdetail.namasupplier 

      WHERE tbdetail.id = {$id} 
      "; 
    return $this->db->query($sql)->result_array(); 
    } 
+0

$ id有什麼? –

+1

id是一個字符串,它的需要引用 –

+0

嘗試打印您的查詢並導致您將得到什麼錯誤....嘗試'print_r($ sql);和print_r($ this-> db-> query($ sql) - > result_array()); ' – Linus

回答

1

看來$id變量包含字符串空格,所以你得到這個錯誤。將其更改爲

public function get_detail($id){ 

    $sql = "SELECT * FROM tbdetail 
      JOIN tbkalibrasi ON tbkalibrasi.id = tbdetail.id 
      JOIN tbsupplier ON tbsupplier.namasupplier = tbdetail.namasupplier 

      WHERE tbdetail.id = '$id' 
      "; 
    return $this->db->query($sql)->result_array(); 
    } 
+0

@irwanDwiyanto,嘗試在$'id上加單引號'查詢變量並檢查它是否有效 –

+0

已經嘗試過,但它仍然不起作用,我稱之爲id(GE-DIS-001),但MySQL不讀GE –

0

您的變量是否缺少id單引號?

public function get_detail($id){ 

$sql = "SELECT * FROM tbdetail 
     JOIN tbkalibrasi ON tbkalibrasi.id = tbdetail.id 
     JOIN tbsupplier ON tbsupplier.namasupplier = tbdetail.namasupplier 

     WHERE tbdetail.id = '{$id}' 
     "; 
return $this->db->query($sql)->result_array(); 
}