Page 2 of 2 FirstFirst 12
Results 11 to 11 of 11

Thread: help with normalized table please

  1. #11
    Join Date
    Sep 2007
    Location
    Maui
    Posts
    642
    Thanks
    284
    Thanked 15 Times in 15 Posts

    Default

    It seems to me you guys (Daniel & James, who have both helped me immensely with php over the years [thank you!]) are making this WAY more complicated than it needs to be. So, hopefully, I can finally help you with something. I may not be understanding exactly what you are trying to do, but this is how I would do it...

    I simplified your table name to make it easier to follow. This is your code...

    Code:
    SELECT article.title, article.ID 
    FROM article, artcat
    WHERE artcat.cat_ID=13 
    AND artcat.art_ID=article.ID 
    AND artcat.cat_ID!=30 
    AND artcat.cat_ID!=29 
    ORDER BY title
    First, I agree with Traq that you need another column... but in the article table, not the artcat table.... a simple 1/0 field that indicates whether the article should be visible or not.

    Code:
    SELECT * FROM articles WHERE art_id IN(SELECT art_id FROM artcat WHERE cat_id = 13) AND `active` = 1 ORDER BY `title`;
    or, without the `active` column...

    Code:
    SELECT * FROM articles WHERE art_id IN(SELECT art_id FROM artcat WHERE cat_id = 13) AND `art_id` NOT IN(29,30, 47,etc) ORDER BY `title`;
    There you have your data with no php filters required. No muss, no fuss.
    Last edited by kuau; 07-04-2011 at 02:48 AM. Reason: added a word

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •