![]() |
Getting DB Result in 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: Getting DB Result in controller (/showthread.php?tid=3861) |
Getting DB Result in controller - El Forum - 10-25-2007 [eluser]Lockzi[/eluser] Hello, here's a problem that's been bothering me for a while now... In the model I've always been using Code: return $query->result(); The problem is that I can't get any information out of that query in the controller. Anyone has any ideas? If you don't understand I can post some code to show even further what I mean if necessary. Cheers, Lockzi Getting DB Result in controller - El Forum - 10-25-2007 [eluser]Jatinder Thind[/eluser] [quote author="Lockzi" date="1193387082"]If you don't understand I can post some code to show even further what I mean if necessary. [/quote] Yes, some code will help. Getting DB Result in controller - El Forum - 10-26-2007 [eluser]MartÃn M.[/eluser] Maybe you are not loading the database library? Maybe you did it in the model but forget to do it in the controller. I can confirm that doing queries to the DB from a controller works perfectly. Getting DB Result in controller - El Forum - 10-26-2007 [eluser]Lockzi[/eluser] Okay, here we go! ![]() Code: function listTopics($f = null) And a controller for demonstration Code: $data['topics'] = $this->forum->listTopics($data['forum']->f_id); To explain even further. The basic problem is that it's returning a looong array since I'm using return result(). If I instead would use return row() it would work perfectly fine, but then I would only get one row. And there's nothing wrong with the code, so don bother with asking questions about that ![]() Cheers, Lockzi Getting DB Result in controller - El Forum - 10-26-2007 [eluser]Lockzi[/eluser] Loads of views of this topic since my last, more explaining, post and still no replies. If you need further explaining/examples please let me know. ![]() Cheers, Lockzi Getting DB Result in controller - El Forum - 10-26-2007 [eluser]mistere[/eluser] What happens if you change your last line FROM: Code: echo ($data['topics']->f_name); Code: echo ($data['topics'][0]->f_name); ? Regards, Eric Getting DB Result in controller - El Forum - 10-26-2007 [eluser]ELRafael[/eluser] ran into many wall but I know I'll get the answer, here, here, here we go again Why don't you use like that? Model file Code: // Controller file Code: // View file Code: <?php foreach ($resultado->result() as $dados) : ?> If you need to get some value or other thing, use in controller Code: if ($result_query->num_rows() > 0) //blah blah blah! Got it? Getting DB Result in controller - El Forum - 10-26-2007 [eluser]Lockzi[/eluser] That actually works! Thanks a lot mistere. ELRafael, that's what I've been doing for all this time. But that would put a strain on my database, since it will do the query twice, and that's something that I would like to avoid if possible, thanks for the reply though! Cheers, Lockzi |