Getting The Highest ID's record in Mysql+PHP

PythonPython Forum LeaderThe Royal RAM
Ok, basically what I have is a table which has got a load of data stored in it.

There is a column calld ID which is unique and is auto_increment.

What I want to do is to extract the row which has the highest ID number and put it into an array.



How can this be done? Thanks

The Royal Ram

Comments

  • ForgeForge Senior Member The Royal RAM
    [php]

    $query = "SELECT * FROM table ORDER BY id DESC LIMIT 1";
    $result = mysql_query($query);

    [/php]

    Should work..
    Can fat people Go skinny Dipping?
  • PythonPython Forum Leader The Royal RAM
    but wont that order the id's from lowest to highest and then only select the top one.

    Wouldnt it need to order them highest to lowest and then only select one?

    The Royal Ram

  • CannonBallGuyCannonBallGuy Moderator Shared Hoster
    It's descending... from highest to lowest.... :)
    Forge wrote:
    $query = "SELECT * FROM table ORDER BY id DESC LIMIT 1";
    $result = mysql_query($query);
  • PythonPython Forum Leader The Royal RAM
    ahh yes i thought so :)

    Thanks

    The Royal Ram

  • aenigmaaenigma Beginner Link Clerk
    $query = "SELECT MAX(ID) AS idmax FROM table";
    $result = mysql_query($query);
    
    Eremita Solitario
    http://www.thekey.it
Sign In or Register to comment.