简体   繁体   English

如何在codeigniter中获取更新的id

[英]how to get updated id in codeigniter

i'm new to Codeigniter, but learning from web, actually i got stuck with a unknown proble.我是 Codeigniter 的新手,但从网络上学习,实际上我遇到了一个未知问题。

im inserting data into the database throw the model, and fetching back the data into form.我向数据库中插入数据会抛出模型,并将数据取回表单。

but when i'm updating the form i want to return the updated id.但是当我更新表单时,我想返回更新后的 ID。

i used $user_id = $this->db->insert_id();我用了$user_id = $this->db->insert_id(); but this is for getting insert id,但这是为了获取插入 ID,

even i tried this即使我试过这个

 $this->db->where('id_colum', $student_id);
 $this->db->update('table_name', $data);
 $user_id = $this->db->insert_id();
 return $user_id;

help me out, Thanks for everything..帮帮我,谢谢你的一切..

Just do like this:只是这样做:

$this->db->where('id_colum', $student_id);
$this->db->update('table_name', $data);
$updated_status = $this->db->affected_rows();

if($updated_status):
    return $student_id;
else:
    return false;
endif;

If it is updated, then return back that $student_id .如果更新,则返回$student_id :) :)

$this->db->where('id_colum', $student_id);
$updatedId = $this->db->get('table_name')->row()->id;

$this->db->where('id', $updatedId);
$this->db->update('table_name', $data);

if($this->db->affected_rows() > 0){
   return $updatedId;
} else {
   return false;
}

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

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