Welcome Guest, Not a member yet? Register   Sign In
storing the value from $this->db->insert_id()
#1

[eluser]The Mask[/eluser]
Hi,
I have a combo control on my form holding titles (Mr, Mrs, Doctor etc). If a required title is not there, the user can enter a value in an <input> box and using ajax, it is saved with the combo control refreshed and defaulting to the new value entered.
When I write the new value, I use $this->db->insert_id() to obtain the new ID. I need this value to pass to a helper I have written that generates the HTML for the combo control so it knows which <option> to default to. Initially, I added a property $last_insert to my Title model (to temporarily store the last insert id) but this then assumed a column in my Title table existed and the save stopped working. To get around it, I created a dummy model that I could then reference in my view. E.g. $this->Dummy->last_insert. This works fine but is there a better way?
Thanks
#2

[eluser]Pascal Kriete[/eluser]
Hmm, I might be way off the mark, here's how I see this. Your model returns the insert_id to the controller. The controller passes this as a parameter to the helper. The helper echos the proper html -> javascript updates the field.
#3

[eluser]The Mask[/eluser]
OK thanks, I will have a look at this option and let you know.
Also, is there a clear definition of what this->db->insert_id() returns and when? I recall I had to grab the value whilst still in the transaction, otherwise it returned zero.
Thanks for your help




Theme © iAndrew 2016 - Forum software by © MyBB