简体   繁体   中英

Show data record using id in codeigniter

i got this error message

Column 'id_siswa' in where clause is ambiguous

SELECT * FROM `siswa` `a` 
LEFT JOIN `pembayaran_spp` `b` ON `b`.`id_siswa`=`a`.`id_siswa` 
WHERE `id_siswa` = '7%E2%80%8B'

I have 2 table.

1.table 'siswa' structure(id_siswa,nama_siswa,id_tahun_masuk)

2.table 'pembayaran_spp'-> structure(id_pembayaran,id_siswa,jml_pembayaran,id_tahun,date)

I want to show data 'pembayaran_spp' by id_siswa. so when i click detail on 'siswa', data 'pembayaran' is showed by id_siswa.

My Controller

function detailtagihan($id_siswa)
    {
            $data['siswa'] = $this->M_keuangan->tagihansiswa($id_siswa);

            $this->load->view('template/header');
            $this->load->view('template/sidebar');
            $this->load->view('keuangan/v_detailtagihan',$data);
            $this->load->view('template/footer');

    }

My Model

function tagihansiswa($id_siswa)
    {
        //$data = array('id_siswa' => $id_siswa );

        $this->db->select('*');
        $this->db->from('siswa a');
        $this->db->join('pembayaran_spp b','b.id_siswa=a.id_siswa', 'left');
        $this->db->where('id_siswa',$id_siswa);

        $query = $this->db->get();
        if($query->num_rows()>0)
            return $query->result();
    }

You should mention of which table you want to use the column id_siswa in your where clause. As both of the tables are having a column with same name, you are getting this error.

If you want to use siswa then in your where condition write a.id_siswa

And if you want to use pembayaran_spp then in your where condition b.id_siswa .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM