SitePoint Sponsor

User Tag List

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

    Synching Most-Recent Articles & Random Article

    When a user chooses a "Section" (e.g. Finance) from the top menu, he/she is taken to a "Section Landing Page", which includes a listing of related "Sub-Sections" (Economy, Markets, Investing).

    Under each "Sub-Section", there are two areas:

    On the right will be a listing of the "4 Most Recent Articles" displayed as hyperlinks.

    On the left, will be a "Featured Article" which will have a Thumbnail and Short Summary (designed to highlight the article).


    Now on to my MySQL questions...

    First, I need to retrieve the "5 Most Recent Articles". (Easy enough)

    Code SQL:
    SELECT a.heading, s.name, a_s.primary_section, a.published_on
    FROM article AS a
    INNER JOIN article_section AS a_s
    ON a.id = a_s.article_id
    INNER JOIN SECTION AS s
    ON s.id = a_s.section_id
    WHERE s.name = 'finance'
    AND published_on < '2012-01-15 00:00:00'
    ORDER BY a.published_on DESC
    LIMIT 5

    Next, I want to randomly grab one of those records and use it for the "Featured Article" on the left.

    Then, the remaining 4 Articles will be used in the right area.

    (**The KEY is that the same Articles should never be displayed in both areas.)


    Follow me?


    Honestly, I'm not sure if this is a MySQL problem, or if I should be handling this with PHP, but I'll see what you guys think...

    Sincerely,


    Debbie

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,323
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by DoubleDee View Post
    Honestly, I'm not sure if this is a MySQL problem, or if I should be handling this with PHP
    the latter
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


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
  •