1

Here is a code where i'm inserting some values to table row. in the next line i want the id of that row. may i know how can i get that. Below is the code.

$data = array(
'i_course_id' => $post_data['course_id'],
'i_cousem_id' => $crs_semister,
'i_event' => $post_data['event'],
'i_event_year' => $year,
'i_stu_crs_random_id' => $studentData['random_id'],
'i_no_scan' => 1
);
$this->db->insert('i_stud_crs', $data);
Jeeva
  • 632
  • 1
  • 12
  • 21

3 Answers3

2

You should get last inserted id with $this->db->insert_id() just after the $this->db->insert('i_stud_crs', $data);

ignasi
  • 443
  • 4
  • 8
2

You can get the last inserted id as:

    $this->db->insert('i_stud_crs', $data);
    $insert_id = $this->db->insert_id();

$insert_id holds the last inserted id.

niriza
  • 21
  • 7
1

Use below code

$data = array(
    'i_course_id' => $post_data['course_id'],
    'i_cousem_id' => $crs_semister,
    'i_event' => $post_data['event'],
    'i_event_year' => $year,
    'i_stu_crs_random_id' => $studentData['random_id'],
    'i_no_scan' => 1
    );
    $this->db->insert('i_stud_crs', $data);
    $id = $this->db->insert_id(); 
vishal shah
  • 316
  • 2
  • 12