[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 ()
{
$query = $this->db->query('SELECT id, firstName, lastName, memberNum, email FROM member');
if ($query->num_rows() > 0)
{
foreach ($query->result() as $row)
{
echo $row->firstName;
echo $row->lastName;
echo $row->memberNum;
echo $row->email;
}
}
}
The Control currently has
Code:
$this->load->database();
$this->load->model('CMS_model');
$query = $this->CMS_model->retrieve_members();
$this->load->view('template');
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