I'm trying to pull customer orders from my database in an array. My database structure has an orders table, then an order_items table that joins on the order ID fields of both tables.
public function getUserOrders($id) {
$this->db->select('*');
$this->db->from('orders');
$this->db->join('order_items', 'order_items.order_id = orders.id', 'left');
$this->db->join('products', 'products.id = order_items.product_id', 'left');
$this->db->where('cust_id', $id);
$this->db->limit(5);
$query = $this->db->get();
$result = $query->result_array();
return $result;
}
I want my array structure to be nested, so that in each order array there is a nested array of products for that order, can I achieve this in my model above?