【发布时间】:2013-09-16 00:10:14
【问题描述】:
我想显示我的数据库中的结果列表。目前,我的视图只显示我的查询检索到的最后一行。我在这里想念什么?感谢您提供的任何帮助。
型号:
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;
}
}
控制器:
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);
}
查看:
<?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;?>
【问题讨论】:
标签: php mysql codeigniter templates foreach