![]() |
Trying to pass variable from 1 Function to Another to Put in Array within same Model - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Trying to pass variable from 1 Function to Another to Put in Array within same Model (/showthread.php?tid=30721) |
Trying to pass variable from 1 Function to Another to Put in Array within same Model - El Forum - 05-24-2010 [eluser]jshultz[/eluser] Ok, that sounds really confusing. What I'm trying to do is this. I've got a function that uploads/resizes photos to the server. It stores the paths in the DB. I need to attach the id of the business to the row of photos. Here's what I have so far: Code: function get_bus_id() { That get's the id of the business. Then, I have my upload function which is below: Code: /* Uploads images to the site and adds to the database. */ The problem I'm getting is the following: Fatal error: Cannot use object of type CI_DB_mysql_result as array in /home/welcomet/public_html/application/models/gallery_model.php on line 48 I've tried all sorts of ways to get the value over, but my limited knowledge keeps getting in the way. Any help would be really appreciated. Trying to pass variable from 1 Function to Another to Put in Array within same Model - El Forum - 05-24-2010 [eluser]zimco[/eluser] Looks like you wanted to return an array from your model but instead you have returned an object then tried to use it as an array. I usually do something like this in my model if i want to return an array: Code: $query = $this->db->get(); Trying to pass variable from 1 Function to Another to Put in Array within same Model - El Forum - 05-24-2010 [eluser]jshultz[/eluser] Ok, I tried that but I'm getting an array to string conversion message. I should only retrieve on record from the get_bus_id function. One account can only have one business associated with it at this time. Trying to pass variable from 1 Function to Another to Put in Array within same Model - El Forum - 05-24-2010 [eluser]jshultz[/eluser] Ok, I tweaked it I think, I'm getting this error now: A PHP Error was encountered Severity: Notice Message: Undefined index: id Filename: models/gallery_model.php Line Number: 48 Line 48 is Code: 'busid'=> $bus_id['id'], my get_bus_id function now looks like this: Code: function get_bus_id() { and I changed the do_upload() function so that it says this: Code: $bus_id = $this->get_bus_id(); Trying to pass variable from 1 Function to Another to Put in Array within same Model - El Forum - 05-24-2010 [eluser]vitoco[/eluser] Try this code, and a question...what happens if the query doesn't return a row ?? Code: function get_bus_id() { Trying to pass variable from 1 Function to Another to Put in Array within same Model - El Forum - 05-24-2010 [eluser]jshultz[/eluser] I'm still receiving this though: Severity: Notice Message: Undefined index: id Filename: models/gallery_model.php Line Number: 48 i've checked my sql query and it should work. when i run the query manually i get the expected result. This line should run the function: $bus_id = $this->get_bus_id(); and this line should take the value and store it in the array: 'busid'=> $bus_id['id'], I've tried it without ['id'] and i got the same results. Trying to pass variable from 1 Function to Another to Put in Array within same Model - El Forum - 05-24-2010 [eluser]vitoco[/eluser] the code was edited and i've added a print_r to see the array data. try again please Trying to pass variable from 1 Function to Another to Put in Array within same Model - El Forum - 05-24-2010 [eluser]D.Phil[/eluser] Line 48 should be: Code: 'busid'=> $bus_id[0]['id'], or you could modify the get bus is function to look like this: Code: function get_bus_id() { Trying to pass variable from 1 Function to Another to Put in Array within same Model - El Forum - 05-24-2010 [eluser]jshultz[/eluser] Array ( [id] => 5 ) Trying to pass variable from 1 Function to Another to Put in Array within same Model - El Forum - 05-24-2010 [eluser]vitoco[/eluser] so it's working...now you must change Code: $data = array( to Code: $data = array( and remove ( or comment to use it later ) the print_r statement |