Query for post and tags in same query

前端 未结 3 564
别那么骄傲
别那么骄傲 2020-12-20 15:33

I have 3 tables with those relevent fields

posts (id,title)
tags (id,name)
tags_map (id,id_post,id_tag)<

3条回答
  •  旧巷少年郎
    2020-12-20 16:21

    Try the below code:

    $this->db->select('pt.*,group_concat(tg.name order by tg.id) as thetags,group_concat(tg.relevance order by tg.id) as therelevances');
    $this->db->from('posts pt');
    $this->db->join('tags_map tm', 'tg.id_post = pt.id');
    $this->db->join('tags tg','tg.id =tm.id_tag');
    $this->db->group_by('pt.id');
    

提交回复
热议问题