one_n00b one_n00b - 5 months ago 20
MySQL Question

Codeigniter Column 'idimport_database' in where clause is ambiguous

I'm having trouble when I want to display data using codeigniter, please help.
I attach the code.

Controller :

public function views($idimport_database)
{
$data['title']=$idimport_database;
$data['header']=$this->m_transaction->detail_transaction($idimport_database)->row_array();
$data['detail']=$this->m_transaction->detail_transaction($idimport_database)->result();
$this->template->load('template','view_data', $data);
}


Model :

function detail_transaction($idimport_database){
$this->db->select('*');
$this->db->from('tbl_import_database');
$this->db->where('idimport_database', $idimport_database);
$this->db->join('tbl_transaksi', 'tbl_transaksi.idimport_database = tbl_import_database.idimport_database');
return $this->db->get();
}


Here result error :

Error Number: 1052
Column 'idimport_database' in where clause is ambiguous
SELECT * FROM `tbl_import_database` JOIN `tbl_transaksi` ON `tbl_transaksi`.`idimport_database` = `tbl_import_database`.`idimport_database` WHERE `idimport_database` = '41' Filename: C:/xampp/htdocs/apriori/system/database/DB_driver.php
Line Number: 691

Answer Source

The error means both tables (tbl_import_database and tbl_transaksi) have a column named idimport_database, and MySQL does not know which one you intend to use in your where statement.

Change the function in your model to include the table name:

$this->db->where('tbl_import_database.idimport_database', $idimport_database);