[英]Codeigniter: Nested Array from DB
我正在尝试从数组中提取数据库中的客户订单。 我的数据库结构有一个orders表,然后是一个order_items表,该表连接到两个表的order ID字段上。
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;
}
我希望嵌套我的数组结构,以便在每个订单数组中都有用于该订单的嵌套产品数组,我可以在上面的模型中实现这一点吗?
CodeIgniter不能从数据库请求中轻松地开箱即用地嵌套数组。 我会考虑使用ORM 。 快速搜索显示了一些,但很有帮助的是, 此Stack Overflow答案可能是最好的选择。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.