I want to display a list of results from my database. Currently, my view is only displaying the last row my query retrieves. What am I missing here? Thanks for any help you can give.
Model:
public function get_agencies() {
$this->db->select("AgencyNumber, AgencyName, users.id, active");
$this->db->from('Agency, users');
$this->db->where('users.id = Agency.id');
$q = $this->db->get();
if($q->num_rows() > 0) {
foreach($q->result() as $agency) {
$data['agencies'] = $agency;
}
return $data;
}
}
Controller:
function modify_agency() {
$this->load->model('ion_auth_model');
$this->data['agencies'] = $this->ion_auth_model->get_agencies();
//added the following 2 lines to load view with header and footer from template
$this->data['main_content'] = 'auth/modify_agency';
$this->load->view('./includes/template', $this->data);
}
View:
<?php foreach ($agencies as $agency):?>
<tr>
<td><?php echo $agency->AgencyNumber;?></td>
<td><?php echo $agency->AgencyName;?></td>
<td><?php if($agency->active == 1) { echo 'Active'; } else { echo 'Inactive'; };?></td>
</tr>
<?php endforeach;?>