![]() |
Using database results in the controller - 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: Using database results in the controller (/showthread.php?tid=40202) |
Using database results in the controller - El Forum - 04-01-2011 [eluser]bcarter[/eluser] Hi there I hope someone can help me as I am really stuck with this. I am using Ion_auth to build my login to an application but the principle is universal, I just don’t know it!!! Problem I want to query a ‘users’ table and use the results to insert into a different table. Here’s the Model… Code: class Login_model extends CI_Model { And the controller… Code: class Campaign extends CI_Controller { Can anyone help or explain (as clearly as possible please, like you’re talking to an idiot ;-) !) how to use data you retrieve from a query in the controller? Thanks! Using database results in the controller - El Forum - 04-01-2011 [eluser]andyy[/eluser] Why are you loading and calling methods from Search_model when you cited a model named Login_model? Have you tried using $query->row_array() instead of $query->row()? I haven't tested it but I don't know if you can return objects from the model to the controller - I've only ever returned arrays. Assuming you used $query->row_array(): Code: function add() Using database results in the controller - El Forum - 04-01-2011 [eluser]haileCI[/eluser] $this->load->model('Search_model');? it is not the Model you difind $query = $this->db->get('users', 1);? i don't know what you want to do,why do you add second parameter? Using database results in the controller - El Forum - 04-01-2011 [eluser]andyy[/eluser] [quote author="haileCI" date="1301689208"] Code: $query = $this->db->get('users', 1); [/quote] The second parameter limits the number of results. http://ellislab.com/codeigniter/user-guide/database/active_record.html#select Using database results in the controller - El Forum - 04-01-2011 [eluser]bcarter[/eluser] Less haste more speed! The reason why a different model is defined is because it's an example error! I just trimmed the code out to use as an example of the problem I have. It's just a principal really, how to use data from a query in the controller! Thanks Using database results in the controller - El Forum - 04-01-2011 [eluser]andyy[/eluser] [quote author="bcarter" date="1301690758"]Less haste more speed! The reason why a different model is defined is because it's an example error! I just trimmed the code out to use as an example of the problem I have. It's just a principal really, how to use data from a query in the controller! Thanks[/quote] Alright good to know ![]() Did you solve your problem? |