0

I have three tables, siswa,tahun_masuk,pembayaran_spp. I want to show last record of id_bulan so i can decrease the total months (12) - last record from id_bulan (1,2...12). so from siswa there is only one id_siswa MY problem is the id_siswa is duplicate. can you fix it. sorry for bad english

#model

    function ambildatasiswa()
        {
            //$this->db->distinct();
            $this->db->select('siswa.*, tahun_masuk.keterangan_tahun_masuk,pembayaran_spp.id_bulan');
            $this->db->from('siswa');
            $this->db->join('tahun_masuk', 'tahun_masuk.id_tahun_masuk=siswa.id_tahun_masuk','left');
            $this->db->join('pembayaran_spp', 'pembayaran_spp.id_siswa=siswa.id_siswa','left');
            return $this->db->get();
        }

#controller
    public function datasiswa()
        {
            $data['siswa'] = $this->M_home->ambildatasiswa()->result();

            $this->load->view('template/header');
            $this->load->view('template/sidebar');
            $this->load->view('v_kepsek/v_datasiswa',$data);
            $this->load->view('template/footer');
        }
#view
    <tbody>
                            <?php $no = 1;
                            foreach ($siswa as $s){
                             $bulan_ini=date('m');   
                            ?>
                            <tr>
                                <td><?php echo $no++ ?></td>
                                <td><?php echo $s->id_siswa ?></td>
                                <td><?php echo $s->nama_siswa ?></td>
                                <td><?php echo $s->keterangan_tahun_masuk ?></td> 
                                </td> <td>
    <a href="<?php  echo base_url('keuangan/detailtagihan/'.$s->id_siswa);?>​">
    <button class="btn btn-info" type="submit" >Detail</button>
                                </a></td>
                                <td>
                                    <?php echo 
                                    $bulan_ini-$s->id_bulan .' Bulan';
                                    ?>         
                                </td>
Catur Ananta
  • 92
  • 12
  • Try a combo of the following questions, [one for limits](https://stackoverflow.com/questions/12086767/update-with-limit-1-in-codeigniter-use-active-record) and [one for sorting](https://stackoverflow.com/questions/5320395/codeigniter-order-by-on-a-query/5320523) – Can O' Spam Jun 28 '18 at 16:04
  • where you want to use the `last` record , you r not using anywhere in your query – Pradeep Jun 28 '18 at 16:51
  • i mean. i just want to use select distinct id_siswa because it is duplicate. i want to select the last insert of id_bulan in pembayaran_spp table. – Catur Ananta Jun 29 '18 at 01:39

0 Answers0