2013-07-11 175 views
0

我需要在数据库表格中提取数据的同时填写表格。然而,当我尝试这样做,它返回的错误:CodeIgniter:从数据库(表格)填充表格(HTML /表格)

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

回答

3

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

试试这个

型号

function roomsTable() { 
    $query = $this->db->select(array('room_number','rt_name'))->get('rooms'); 
    return $query; //<---here 
} 
+0

谢谢你,你很快。有效!现在我必须等待几分钟才能接受这个答案。 :) –

+1

:) ..欢迎...很高兴它帮助...快乐编码.. :) – bipen