Reputation: 71
I want to show room type and rooms number inside it example:
and so on.
this is my table
room_type
-------
room_type_id (int)
room_type_name (varchar)
room_price (float)
room_detail (text)
room
-------
room_e_id (int)
room_type_id (int)
room_number (int)
room_status (varchar)
Here's my Model
function get_room_type() {
$query = $this->db->get('room_type');
$return = array();
foreach ($query->result() as $room) {
$return['$room->room_type_id'] = $room;
$return['$room->room_type_id'] -> subs = $this->get_room_list($room->room_type_id);
} return $return;
}
public function get_room_list($room_type_id) {
$this->db->where('room_type_id', $room_type_id);
$query = $this->db->get('room');
return $query->result();
}
And this is my Controller
$data['room_list'] = $this->m_fo->get_room_type();
And view
<ul>
<?php foreach ($room_list as $row) { ?>
<li>
<?php echo $row->room_type; ?> <?php
if (!empty($row->subs)) {
echo '<ul>';
foreach ($row->subs as $sub) {
echo '<li>' . $sub->room_no . ' - ' . $sub->room_status . '</li>';
} echo '</ul>';
}
?>
</li> <?php } ?>
</ul>
but it's only show the last room type and room number in my page as you can see here -- screenshot is anything wrong or less? Thanks You
Upvotes: 0
Views: 45
Reputation: 12085
Inside the single quotes everything consider as string so you should change these two lines like this .
$return[$room->room_type_id]->rooms = $room;
$return[$room->room_type_id]->subs = $this->get_room_list($room->room_type_id);
Upvotes: 1