Reputation: 15
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.
Upvotes: 1
Views: 54
Reputation: 8960
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)
Upvotes: 1
Reputation: 5444
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();
Upvotes: 0