SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Evangelist jkh1978's Avatar
    Join Date
    May 2001
    Location
    Northern Virginia
    Posts
    445
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    last 3 database entries

    With a php site connected to a mysql database, what is the best way to chose the last 3 entries made?

    Also, is there a way to sort the results and get like the 5th one?

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Assuming you have a timestamp field in your table, you can do this to get the last three entries.

    Code:
    SELECT * from tablename ORDER BY timestamp DESC LIMIT 3;
    To get the fifth one

    Code:
    SELECT * from tablename ORDER BY timestamp DESC LIMIT 4,1;
    Please don't PM me with questions.
    Use the forums, that is what they are here for.


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
  •