0

我需要用从数据库表中提取的数据填写视图中的表。但是,当我尝试这样做时,它返回了错误:

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');
}
4

1 回答 1

4

那是因为您忘记在模型中返回数据。

尝试这个

模型

 function roomsTable() {
   $query = $this->db->select(array('room_number','rt_name'))->get('rooms');
   return $query;  //<---here
}
于 2013-07-11T10:33:56.933 回答