SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Mar 2003
    Location
    Ireland
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Finding last submitted entry in database?

    Is there a quick way to find the last 3 submitted entries of a database with out using SELECT(*) and then a count down loop?

    Thanks,
    Matt

  2. #2
    SitePoint Wizard Crowe's Avatar
    Join Date
    Nov 2001
    Location
    Huntsville
    Posts
    1,117
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You don't need a count down loop, just limit.

    PHP Code:
    select from table_name order by ID DESC limit 3 
    Should grab the last three if you have an ID field that is auto_increment.
    Chrispian H. Burks
    Nothing To Say

  3. #3
    As the name suggests... trickie's Avatar
    Join Date
    Jul 2002
    Location
    Melbourne, Australia
    Posts
    678
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  4. #4
    SitePoint Wizard Crowe's Avatar
    Join Date
    Nov 2001
    Location
    Huntsville
    Posts
    1,117
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    That's not what he's looking for here. He wants the last three submitted, that gives you the id of the last entry you inserted to the dabase (which is also a very handy bit of code!).
    Chrispian H. Burks
    Nothing To Say

  5. #5
    SitePoint Zealot
    Join Date
    Mar 2003
    Location
    Ireland
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the help, it works a treat


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
  •