php - How do I SELECT my content and all the tags that go with it? -
i've tried hard have normalized database , have 3 tables -
- content (c)
- content_tags (ct)
- tags (t)
what i'm trying here select rows , return them tags associated it. @ moment, returns 1 tag reason.
here code i'm using:
select *, group_concat(t.tag) tags content c left join category ca on c.cid = ca.cid left join contenttags ct on c.smid = ct.smid left join tags t on ct.tid = t.tid left join users u on c.uid = u.uid (t.tag in ('tag1', 'tag2', 'tag3')) group c.smid it returns this:
- cid
- content
- url
- tag (but 1 instead of multiple)
do mean find contents , tags, @ least 1 of tag in $tagarray ?
select c.*, ca.*, u.*, group_concat(t.tag) tags content c left join category ca on c.cid = ca.cid join contenttags ct on c.smid = ct.smid join tags t on ct.tid = t.tid left join users u on c.uid = u.uid exists ( select * contenttags ct2 join tag t2 on t2.tid = ct2.tid ct2.smid = c.smid , ct2.tag in ('$tagarray') ) group c.smid and left join can turned inner joins, too, without losing results. try it. unless category.cid or category.uid fields can have null values. in case, keep related left join.
Comments
Post a Comment