SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Wizard bronze trophy
    Join Date
    Apr 2003
    Posts
    4,095
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question A way to select the most recent five entries in a database?

    Hello everyone,

    I'm wondering if it's possibly for a PHP script to automatically retrieve the most recent five entries in a MySQL database. Can such a thing be done?

    Thanks for your your help.

    Compuwhiz7

  2. #2
    SitePoint Addict Ramiro S's Avatar
    Join Date
    May 2003
    Posts
    321
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, if you have a date or the IDs are autoincremental... use ORDER BY thefield DESC LIMIT 5 in your select query
    Quasar - Web Development - Free Avatars

  3. #3
    SitePoint Wizard bronze trophy
    Join Date
    Apr 2003
    Posts
    4,095
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello, everyone,

    Quote Originally Posted by Ramiro S
    Yes, if you have a date or the IDs are autoincremental... use ORDER BY thefield DESC LIMIT 5 in your select query.
    So it would be something like:

    PHP Code:
    [email=$latest=@mysql_query(]$latest=@mysql_query("select[/email] * from latest order by id desc limit 5"); 
    Would that work?

    Thanks for your help.

    Compuwhiz7

  4. #4
    SitePoint Addict Ramiro S's Avatar
    Join Date
    May 2003
    Posts
    321
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes if id is autoincrement
    Quasar - Web Development - Free Avatars

  5. #5
    SitePoint Wizard bronze trophy
    Join Date
    Apr 2003
    Posts
    4,095
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello everyone,

    Thanks for the help!

    Compuwhiz7


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
  •