简体   繁体   English

在Codeigniter中使用ID显示数据记录

[英]Show data record using id in codeigniter

i got this error message 我收到此错误消息

Column 'id_siswa' in where clause is ambiguous where子句中的“ id_siswa”列不明确

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. 我有2张桌子。

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

2.table 'pembayaran_spp'-> structure(id_pembayaran,id_siswa,jml_pembayaran,id_tahun,date) 2.表'pembayaran_spp'->结构(id_pembayaran,id_siswa,jml_pembayaran,id_tahun,日期)

I want to show data 'pembayaran_spp' by id_siswa. 我想显示id_siswa的数据“ pembayaran_spp”。 so when i click detail on 'siswa', data 'pembayaran' is showed by id_siswa. 因此,当我单击“ siswa”的详细信息时,id_siswa会显示数据“ pembayaran”。

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. 您应该在where子句中提到要使用哪个表id_siswa表。 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 如果要使用siswa ,请在您的where条件中编写a.id_siswa

And if you want to use pembayaran_spp then in your where condition b.id_siswa . 如果要使用pembayaran_spp则在您的where条件b.id_siswa

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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