Postingan lainnya
Error number: 1052(ambiguous) mengambil data dari tabel lain yang di join berdasarkan id
saya mau mengambil data berdasrkan user login di tb_data menggunakan relasi dengan tb_users, namun terjadi error ambiguous
Error Number: 1052
Column 'id_user' in where clause is ambiguous
SELECT `tb_data`.*, `tb_users`.`nama_user`, `tb_users`.`username`, `tb_users`.`akses_level`, `tb_users`.`nama_panggilan`, `tb_users`.`keterangan` FROM `tb_data` RIGHT JOIN `tb_users` ON `tb_data`.`id_user` = `tb_users`.`id_user` WHERE `id_user` IS NULL ORDER BY `id_user`
Filename: C:/xampp/htdocs/inkomunjani/system/database/DB_driver.php
Line Number: 691
public function getData($id_data)
{
$this->db->select('tb_data.*, tb_users.nama_user, tb_users.username, tb_users.akses_level, tb_users.nama_panggilan, tb_users.keterangan');
$this->db->from('tb_data');
//join db
$this->db->join('tb_users', 'tb_data.id_user = tb_users.id_user', 'right');
//end join db
$this->db->where('id_user', $id_data);
$this->db->order_by('id_user');
$query = $this->db->get();
return $query->row();
}
3 Jawaban:
Jawaban Terpilih
Bisa seperti ini tak gan
<pre> $this->db->where('tb_users.id_user', $id_data); $this->db->order_by('tb_users.id_user'); </pre>
<div>kalo untuk login dari dua table gimana yah mas... <br><br><br>class Auth_m extends CI_Model<br>{<br> public function login($nik, $password)<br> {<br> $this->db->select('*');<br> $this->db->from('user, akun');<br> $this->db->where('nik', $nik);<br> $this->db->where('password', $password);<br> $this->db->limit(1);<br> $query = $this->db->get();<br><br> if ($query->num_rows() == 1) {<br> return $query->result();<br> }<br> }<br>}</div><pre><br></pre>