简体   繁体   中英

how to join a two tables with arrays of datas

My first table category contain categoryid and categories .
Second table bloggers contains bloggercategory .
bloggercategory contain array of categoryid (more than one categoryid ).

function selectusercategories($sess_id) 
{
   $this->db->select('*');
   $this->db->from('categories');
   $this->db->join('bloggers', 'blogger_category = category_ID');
    $this->db->where('ID', $sess_id);
   $querycat = $this->db->get();
   return $querycat->result();
}

Can I join the two tables to display the bloggercategory individualy from the array with its categories . I tried this way but its not working.

For comma separated field, use MySQL FIND_IN_SET()

SELECT  *
FROM    categories c
JOIN    bloggers b
ON      FIND_IN_SET(c.category_ID ,b.blogger_category)

Try this..

$this->db->select("*");
  $this->db->from('categories');
  $this->db->join('bloggers', 'categories.category_ID= bloggers.blogger_category ');
  $query = $this->db->get();
  return $query->result();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM