2013-07-11 211 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