![]() |
Query database and insert result in an existing array - 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: Query database and insert result in an existing array (/showthread.php?tid=57356) |
Query database and insert result in an existing array - El Forum - 03-08-2013 [eluser]keugant[/eluser] Hello everyone, I'm currently working on a community site built with CodeIgniter and I keep bumping into an error while trying to insert some data in an existing array. I'm new to the MVC pattern and to the framework itself so please excuse any obvious error. Here is the problem and source code: I query the database to get a list of groups (in the model): Code: public function view_groups() { Then, while the results are passed to the controller, I send them back to another function to check if the current user have joined the group: Controller: Code: public function groups() { Model: Code: public function is_joined($group_id) { The purpose is to get the existing groups (that can be created by users), I check if the current user is part of them or not (detail stored in the interface_group table). But, all I get is a blank page.. Could you please help. Thank you Query database and insert result in an existing array - El Forum - 03-08-2013 [eluser]CroNiX[/eluser] Code: foreach($results as $row) { Try changing it to Code: foreach($results as &$row) {//pass by reference - use ampersand Code: $row->status => 'true'; // or false Query database and insert result in an existing array - El Forum - 03-08-2013 [eluser]keugant[/eluser] Thank you very much, I didn't know about this technique. Maybe you could tell me about a different approach to achieve what I'm trying to do, in theory at least. Should I use two functions in the model or only one? Should I link the two in the controller? Thanks ![]() Query database and insert result in an existing array - El Forum - 03-10-2013 [eluser]keugant[/eluser] Thank you sorry I typed it wrong, but this is definitely the solution ![]() Thanks a lot ![]() |