SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Evangelist
    Join Date
    Nov 2001
    Location
    UK
    Posts
    553
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Selecting The Latest Additions

    Is is possible, to select the latest 4 or 5 or 6 additions to a database. For example, I want a script to select the latest 6 articles which have been added to my site.

    I expceted that I could use a WHILE statement, but I don't know how to stop this after it has shown the latest six additions. Also, I didn't know how to show the LATEST six, as opposed to the first six.
    Regards, Ant.

  2. #2
    Feel my RewiredMind KMxRetro's Avatar
    Join Date
    Jan 2001
    Location
    Exeter, Devon, UK
    Posts
    477
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi there,
    If you have something like an article ID or date/time in the database records, you could use something like this:-

    Code:
     SELECT * FROM table SORT BY id DESC, LIMIT 5
    The LIMIT makes MySQL stop reading after it has found 5 records, and to make sure that you have the latest records in the resultset, the SORT BY id DESC argument makes sure that MySQL is reading the records from bottom to top, rather than top to bottom. The latest additions will be on the bottom so it'll read latest > 2nd latest > 3rd latest etc etc

    Hope this helps!

  3. #3
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it's ORDER BY, not SORT BY.
    - Matt ** Ignore old signature for now... **
    Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
    "Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR

  4. #4
    Feel my RewiredMind KMxRetro's Avatar
    Join Date
    Jan 2001
    Location
    Exeter, Devon, UK
    Posts
    477
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oops! My bad....

    I always do that

  5. #5
    SitePoint Member
    Join Date
    Dec 2001
    Location
    Brazil
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why is it I cant see what KMxRetro wrote? I tried to change my options but I still cant see it.

    In the topic of sortin data maybe you could help me:
    I need to show the 10 highest scores for a quiz. Havent figured out a way to do it yet.
    Actually I have troubel with the syntax for sorting and orderin data.

    thanks.

  6. #6
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    SELECT * FROM table ORDER BY score LIMIT 10

    1) KMxRetro edited his post

    2) You should have started another thread rather than posting in this one

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  7. #7
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by webwing
    Why is it I cant see what KMxRetro wrote? I tried to change my options but I still cant see it.
    are you using Netscape? i remember there used to be a problem with the [ code] tags in NS. so, that may be the reason.


    Originally posted by seanf
    1) KMxRetro edited his post
    ...?

  8. #8
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ooops! I need to put my glasses on

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  9. #9
    SitePoint Member
    Join Date
    Dec 2001
    Location
    Brazil
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks seanf,

    i should started another thread, yes.
    but by now I have already figured a bit more about how to order data and solved my problem.

    anyway thanks again.


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
  •