0

I need to fill in a table in my view with the data extracted from a database table. However when I tried this, it returned error:

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

View:

<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>

Controller:

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

Model:

function roomsTable() {
    $query = $this->db->select(array('room_number','rt_name'))->get('rooms');
}

1 Answer 1

4

That is because you forgot to return data in your model.

try this

Model

 function roomsTable() {
   $query = $this->db->select(array('room_number','rt_name'))->get('rooms');
   return $query;  //<---here
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you and you were quick. It worked! Now I have to wait for few minutes to accept this as the answer by the way. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.