Welcome Guest, Not a member yet? Register   Sign In
loading the results of a foreach
#1

[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


Messages In This Thread
loading the results of a foreach - by El Forum - 01-30-2009, 06:22 PM
loading the results of a foreach - by El Forum - 01-30-2009, 06:31 PM
loading the results of a foreach - by El Forum - 01-30-2009, 06:56 PM



Theme © iAndrew 2016 - Forum software by © MyBB