I should update the last ID in mysql, how to ... ...
< Code> $ this- & gt; Db- & gt; Insert ('mytable', $ data); $ Id = $ this- & gt; Db- & gt; Insert_id ();
Then .. $ id is my last id, but I want to get the "last id" in the update function of the model.
You can try to make a refund on $ ID; In your post you said that you wanted to get the last update ID but you did insert.
The update was not tested but tested on inserting.
Model
Enter public function () {$ id = $ this- & gt; Db- & gt; Insert_id (); $ This- & gt; Db- & gt; Insert ('mytable'); Return $ id; } Public Function addData ($ id, $ data) {$ data = array ('username' = & gt; $ this-> input- & gt; post ('username')); $ This- & gt; Db- & gt; Insert ('otherwise', $ data); }
Controller
Public function index () {$ this-> Load-> Model ('yourmodel'); $ Id = $ this- & gt; Yourmodel- & gt; Insert (); $ This- & gt; Yourmodel- & gt; Add data ($ id, $ this-> Input-> Post ()); }
No comments:
Post a Comment