0

i have question. I have 2 tabel, name is 'tbl_pendidikan' and 'tbl_datapribadi'. And i have Model, name is M_pascasarjana.php

function pendidikan($table,$data) {
  $this->db->select_max('id_pendaftar');
  $get_id = $this->db->get('tbl_datapribadi');
  $query = $this->db->insert($table,$data);

} //END FUNCTION//

This is my controller

foreach($_POST['user'] as $user) {
    $this->m_pascasarjana->pendidikan('tbl_pendidikan', $user);
  }

I try to get last id from table 'tbl_datapribadi'. How to insert last id to table 'tbl_pendidikan'?

Touheed Khan
  • 2,149
  • 16
  • 26
syaifulhusein
  • 269
  • 2
  • 8
  • 18

1 Answers1

4
function pendidikan($table,$data) {
    $last_row = $this->db->select('id_pendaftar')->order_by('id_pendaftar',"desc")->limit(1)->get('tbl_datapribadi')->row()->id_pendaftar;
    $data['column_name'] = $last_row;
    $query = $this->db->insert($table,$data);
    return $this->db->insert_id();
} 

$last_row will hold the last id present in tbl_datapribadi table. column_name will be your column name for last inserted id.

Touheed Khan
  • 2,149
  • 16
  • 26