Welcome Guest, Not a member yet? Register   Sign In
Basic Syntax Question
#1

[eluser]alanphil[/eluser]
I'm starting to use Models, and have a basic syntax question. In the past I would do this in the controller:

Code:
$data['query'] = $this->db->get('contacts');
$this->load->view('welcome_message', $data);

and was able to display the data in the view with no problem. Now I'm trying to move the DB logic into a model and running into problems. In the model I have the following function:

Code:
function get_test() {
  $query = $this->db->get('contacts');
  return $query->result();
}

In the controller I have:

Code:
function index(){
    $data['query'] = $this->Mdl_contacts->get_test();
        $this->load->view('welcome_message', $data);
}

and in the view I have:

Code:
<?php foreach ($query->result() as $row): ?>
<p>&lt;?=$row->first_name?&gt; &lt;?=$row->last_name?&gt;<br />
&lt;?=$row->phone?&gt;</p>
&lt;?php endforeach; ?&gt;

My view isn't displaying the data from the DB, and I'm going around in circles looking for a good simple example like this. Thanks for any light you can shine on this simple problem. Smile

Alan


Messages In This Thread
Basic Syntax Question - by El Forum - 07-03-2008, 08:42 AM
Basic Syntax Question - by El Forum - 07-03-2008, 08:46 AM
Basic Syntax Question - by El Forum - 07-03-2008, 08:48 AM
Basic Syntax Question - by El Forum - 07-03-2008, 08:54 AM



Theme © iAndrew 2016 - Forum software by © MyBB