Codeigniter多表联接但结果可获取

时间:2019-06-08 12:43:20

标签: codeigniter jointable

   // $courses    =   $this->db->select('c.id,c.title,c.price,c.discount_flag,c.discounted_price, c.user_id, c.product_type,  
    $courses    =   $this->db->select('c.*,  
        concat(u.first_name," ", u.last_name) username, 
        Group_CONCAT(r.ratable_id) count_rating, avg(r.rating) avg,
        count(e.course_id) count_enroll,
        GROUP_CONCAT(e.course_id),
        GROUP_CONCAT(r.id)
        ')
    ->where_in('c.id', $course_id)
    ->from('course c')
    ->join('users u', 'u.id = c.user_id','left')
    ->join('rating r', 'r.ratable_id = c.id', 'right')
    ->join('enroll e', 'c.id = e.course_id ','right')
    ->distinct('count_enroll,e.id')
    ->get();
    var_dump($courses->result_array());
    return $courses;

我使用此代码将结果赋予可收款

* * *

  count_rating' => string '21,21,21,21' (length=11)

  'avg' => string '3.5' (length=3)

  'count_enroll' => string '4' (length=1)
  'GROUP_CONCAT(e.course_id)' => string '21,21,21,21' (length=11)
  'GROUP_CONCAT(r.id)' => string '2,3,2,3' (length=7) (wrong line)

* * *

'GROUP_CONCAT(r.id)' => string '2,3,2,3' (length=7),这是错误行

0 个答案:

没有答案