I'm having a controller that fetches an array from a model and sends it to the view. Sample table
user id user name user email
1 Mike mike@yahoo.com
2 Tom Tom@live.com
Now I've added another function to the model to fetch another array of data from another table for each user in that table to look like this
user id user name user email
1 Mike mike@yahoo.com
order:10 order total:50 order date: 2016-09-12
order:12 order total:100 order date: 2016-09-14
2 Tom Tom@live.com
order:15 order total:80 order date: 2016-09-13
order:16 order total:120 order date: 2016-09-14
order:17 order total:140 order date: 2016-10-10
Controller's index() function contains this code
$this->data['users'] = $users; //fetches data from a model function
$this->data['content'] = $this->load->view('users_view', $this->data);
So I have the function orders($user_id) that fetches orders from DB for a user. The view code:
<table>
<tr>
<th>
<?php echo 'user id';?>
</th>
<th>
<?php echo 'user name';?>
</th>
<th>
<?php echo 'user email';?>
</th>
</tr>
<?php foreach($users as $val){
?>
<tr>
<td>
<?=$val->user_id?>
</td>
<td>
<?=$val->user_name;?>
</td>
<td>
<?=$val->user_email;?>
</td>
</tr>
<?php
// how to call the model function here and loop through the orders array to
display orders for each user?
}?>
</tbody>
</table>