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 -

  1. content (c)
  2. content_tags (ct)
  3. 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

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -