foodorders
foodorders_id foodorders_price foodorders_status
1 100 1
2 20 1
3 30 1
foodorders_detail
foodorders_detail_id(AI,PK) foodorders_id foodorders_foodname foodorders_lines
1 1 burgers 1
2 1 fries 2
3 1 chips 3
4 2 chips 1
5 3 drinks 1
5 3 bars 2
我想要的是:检查有多少行具有相同的食物订单id并返回到控制器
我尝试过的:
$this->db->select('foodorders.foodorders_price,foodorders.status,COUNT(foodorders_detail.foodorders_lines');
$this->db->from('foodorders');
$this->db->join('foodorders_detail', 'foodorders_detail.foodorders_id = sales.foodorders_id', 'left');
将foodorders.foodorders_id添加到您的选择列中,并将group-by添加到查询中,然后将结果作为对象或数组:
提示:使用别名缩短代码。
$this->db->select('foodorders.foodorders_id,foodorders.foodorders_price,foodorders.status,COUNT(foodorders_detail.foodorders_lines)');
$this->db->from('foodorders');
$this->db->join('foodorders_detail', 'foodorders_detail.foodorders_id = foodorders.foodorders_id', 'left');
$this->db->group_by('foodorders.foodorders_id');
$query = $this->db->get();
return $query->result();