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

avatar waziat
@waziat

23 Kontribusi 5 Poin

Diperbarui 2 tahun yang lalu

3 Jawaban:

Jawaban Terpilih

Bisa seperti ini tak gan

<pre> $this-&gt;db-&gt;where('tb_users.id_user', $id_data); $this-&gt;db-&gt;order_by('tb_users.id_user'); </pre>

avatar mltobing
@mltobing

114 Kontribusi 77 Poin

Dipost 5 tahun yang lalu

terimaksih gan, udah bisa dengan cara itu.

avatar waziat
@waziat

23 Kontribusi 5 Poin

Dipost 5 tahun yang lalu

<div>kalo untuk login dari dua table gimana yah mas... <br><br><br>class Auth_m extends CI_Model<br>{<br>&nbsp; &nbsp; public function login($nik, $password)<br>&nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; $this-&gt;db-&gt;select('*');<br>&nbsp; &nbsp; &nbsp; &nbsp; $this-&gt;db-&gt;from('user, akun');<br>&nbsp; &nbsp; &nbsp; &nbsp; $this-&gt;db-&gt;where('nik', $nik);<br>&nbsp; &nbsp; &nbsp; &nbsp; $this-&gt;db-&gt;where('password', $password);<br>&nbsp; &nbsp; &nbsp; &nbsp; $this-&gt;db-&gt;limit(1);<br>&nbsp; &nbsp; &nbsp; &nbsp; $query = $this-&gt;db-&gt;get();<br><br>&nbsp; &nbsp; &nbsp; &nbsp; if ($query-&gt;num_rows() == 1) {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return $query-&gt;result();<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; }<br>}</div><pre><br></pre>

avatar hadisaputra_google_6435
@hadisaputra_google_6435

2 Kontribusi 0 Poin

Dipost 2 tahun yang lalu

Login untuk ikut Jawaban