0

I tried to call up data by 'id' format id example id = GE-DIS-001 to JOIN table with Codeigniter , the result of "Unknown column ' GE ' in 'where clause ' what's wrong ??

Controller :

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


   }    

Model :

    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();
    }   
irwan Dwiyanto
  • 321
  • 3
  • 7
  • 19

2 Answers2

1

It seems $id variable contains string with spaces, so you are getting this error. Change it to

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();
    } 
Harshit
  • 5,147
  • 9
  • 46
  • 93
0

Is your variable for id missing single quotes?

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();
}
JeredM
  • 897
  • 1
  • 14
  • 25