I can't get a simple id |
[eluser]Sein Kraft[/eluser]
I cant get the last added id (is an autoincrement id in sql) to use in other table. Model: Code: function id() Error: Quote:A PHP Error was encountered
[eluser]Pascal Kriete[/eluser]
Judging by the error, and seeing as it's thrown in the parser, I think the query works fine. You're not grabbing the result. I think what you're looking for is: Code: return $query->row(); Check out the query result documentation for more info.
[eluser]Sein Kraft[/eluser]
Yes, I've tried grab the result using row but this throw the next error Quote:Fatal error: Call to undefined method CI_DB_mysql_driver::row() in E:\server\htdocs\libelula\system\application\models\model_imageboard.php on line 48
[eluser]Sein Kraft[/eluser]
Yes, I've tried grab the result using row but this throw the next error Quote:Fatal error: Call to undefined method CI_DB_mysql_driver::row() in E:\server\htdocs\libelula\system\application\models\model_imageboard.php on line 48
[eluser]Pascal Kriete[/eluser]
Ok, it might be the query after all then. Code: return ($query->num_rows() > 0) ? $query->row() : FALSE; If that returns false the query isn't returning anything. Also, I'm curious in what situation you only need the id?
[eluser]Sein Kraft[/eluser]
It doesn't work :S Quote:Fatal error: Call to undefined method CI_DB_my::num_rows() in E:\server\htdocs\libelula\system\application\models\model_imageboard.php on line 48 I need the id of the latest record to insert in another table. When I upload a image i assign an id (auto-increment in sql), then i need retrieve that id and insert in other table where the id is inserted with a tag system. For Example: I have a form with two inputs, one for the file and other for the tags who represent the image. For the first instance I insert in the table (images) the data of the uploaded image. Next I need retrieve the id of the uploaded image from the table (images) and get the tags from the second input of the form and save in the table (tags). Code: function insert($data) Function id() is a test function because I can't do this work.
[eluser]Pascal Kriete[/eluser]
Right now you're not querying for the id at all, you need to add a ->get(). However, I had a hunch you were trying to do this. There's a helper function that you might find helpful : Code: $this->db->insert_id();
[eluser]Sein Kraft[/eluser]
[quote author="inparo" date="1221337876"]Right now you're not querying for the id at all, you need to add a ->get(). However, I had a hunch you were trying to do this. There's a helper function that you might find helpful : Code: $this->db->insert_id(); And from where gets the id the function?
[eluser]Pascal Kriete[/eluser]
It has access to the connection identifier, so in the case of mysql it'll use mysql_insert_id.
|
Welcome Guest, Not a member yet? Register Sign In |