[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><?=$row->first_name?> <?=$row->last_name?><br />
<?=$row->phone?></p>
<?php endforeach; ?>
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.
Alan