我需要在视图中使用从数据库表中提取的数据填写表格。但是,当我尝试这个时,它返回错误:
Fatal error: Call to a member function result_array() on a non-object in C:\xampp\htdocs\bit\application\views\admin\add_new_room.php on line 32
查看:
<table class="table table-hover">
<?php foreach ($query->result_array() as $row): { ?> // Line 32
<tr>
<td><?php echo $row['room_number'];?></td>
<td><?php echo $row['rt_name'];?></td>
<td><?php echo $row['housekeeping_status'];?></td>
</tr>
<?php } ?>
<?php endforeach; ?>
</table>
控制器:
function index() {
$this->load->model('admin/edit_other_details');
$roomType['rt_name'] = $this->edit_other_details->get_room_details();
$data['query'] = $this->edit_other_details->roomsTable();
$tmp = array_merge($roomType, $data);
$this->load->view('/admin/add_new_room', $tmp);
}
型号:
function roomsTable() {
$query = $this->db->select(array('room_number','rt_name'))->get('rooms');
}
答案 0 :(得分:4)
这是因为您忘记在模型中返回数据。
试试这个
<强>模型强>
function roomsTable() {
$query = $this->db->select(array('room_number','rt_name'))->get('rooms');
return $query; //<---here
}