SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,777
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Determine if Article is in results?

    On my website, an "Article" can be in different "Sections", and a "Section" can have many "Articles".

    When a user selects an Article, I want to be sure that the URL has a valid "Section" for the given "Article" and visa-versa, e.g.

    http://local.debbie/finance/articles/postage-meters-can-save-you-money


    Below is a query I am working on...

    Code SQL:
    			$q1 = 'SELECT id, title, description, keywords,
    							heading, sub_heading, published_on, author,
    							body, reference_listing, endnote_listing
    				FROM article AS a
    				RIGHT OUTER JOIN article_section AS a_s
    				ON a.id = a_s.article_id
    				WHERE slug=?
    				AND a_s.section_id=?';


    If I want to check that the Article "postage-meters-can-save-you-money" is in the "finance" Section (along with possibly other Sections), how do I need to modify the above query??

    Do I want an INNER JOIN looking for an exact match, or a RIGHT OUTER JOIN just making sure the "Section" is in set of all Sections related to the Article?

    Hope that makes sense?!

    Thanks,


    Debbie

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,500
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by DoubleDee View Post
    If I want to check that the Article "postage-meters-can-save-you-money" is in the "finance" Section (along with possibly other Sections), how do I need to modify the above query?
    If that's all you want to do with the query, then use an INNER JOIN.
    Quote Originally Posted by DoubleDee View Post
    the "Section" is in set of all Sections related to the Article?
    Hope that makes sense?!
    To me, this last part doesn't make sense

  3. #3
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,777
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by guido2004 View Post
    If that's all you want to do with the query, then use an INNER JOIN.

    To me, this last part doesn't make sense
    I meant that I was originally thinking of doing a RIGHT OUTER JOIN, finding all Sections that the Article "postage-meters-can-save-you-money" was located in (e.g. "Finance" and "Operations"), and then maybe use the SQL "IN" keyword/whatever to see if the "Section" in the URL was "inside of" the list of all Sections that are associated with the Article.

    Follow me?

    But after I made my original post, I decided to do what you aid above, and just went with an INNER JOIN.

    Thanks,


    Debbie


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
  •