loading the results of a foreach - 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: loading the results of a foreach (/showthread.php?tid=15290) |
loading the results of a foreach - El Forum - 01-30-2009 [eluser]Unknown[/eluser] I am new to working with MVC and am struggling with having my result set load properly. I believe my model should only consist of the query to the database. But currently it does the foreach as well. Code: function retrieve_members () The Control currently has Code: $this->load->database(); When I move the foreach to the control, I am told "Call to a member function num_rows() on a non-object .... on line 25" I am obviously accessing the model incorrectly. Where am I going wrong? Thank you loading the results of a foreach - El Forum - 01-30-2009 [eluser]Pascal Kriete[/eluser] You need to return something to the controller. Right now you're just echoing (adding to the browser output). You could return the result set if you have results: Code: function retrieve_members() I prefer just returning the $query object, but let's use the above example - the controller could be: Code: $data['members'] = $this->CMS_model->retrieve_members(); And then loop through $members in the view and show the details (or do whatever you need to with the data, I obviously don't know where this is going). Hope that helps. Welcome to CodeIgniter. loading the results of a foreach - El Forum - 01-30-2009 [eluser]Unknown[/eluser] Thank you PascalKriete for the quick response. That worked great. I just wasn't aware of the return. Thanks for the warm welcome to the CodeIgniter community. For future reference: MODEL Code: function retrieve_members () Code: function index() Code: echo "<table>"; |