I want get the last id updated in mysql, something how ...:
$this->db->insert('mytable', $data);
$id = $this->db->insert_id();
Then.. $id is my last id, but I want get the "last id" in a update function of the model.
I want get the last id updated in mysql, something how ...:
$this->db->insert('mytable', $data);
$id = $this->db->insert_id();
Then.. $id is my last id, but I want get the "last id" in a update function of the model.
You could try need to put a return on $id;. In your post you said you wanted to get last update id but you had insert.
Untested on update but tested on insert.
Model
public function insert() {
$id = $this->db->insert_id() ;
$this->db->insert('mytable');
return $id;
}
public function addData($id, $data) {
$data = array(
'username' => $this->input->post('username')
);
$this->db->insert('anothertable', $data);
}
Controller
public function index() {
$this->load->model('yourmodel');
$id = $this->yourmodel->insert();
$this->yourmodel->addData($id, $this->input->post());
}