Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Aug 2002
    Location
    Frankfurt/Germany
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    finding record with the highest ID

    hot mornig people!

    since yesterday i trie to find a solzution for my problem:

    i am searching for a posibility to find the record with the highest id

    use:

    i have a couple of records for displaying members of my community.the position in the list is definied by the variable POSITION. if i want to add a member i need to find the last member or the highest position id to init the new record with (highest position value+1)

    but i dont know the query for finding the record with the highest position value. reading the select syntax @ mysql.com has not helped me.

    anyone has a glue?

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    577
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If you set 'id' to auto-increment, mysql would just add one to the highest value when you inserted a blank.

    Anyway
    $addthis = mysql_query("SELECT id FROM `table` ORDER BY id DESC LIMIT 1");
    Ökii - formerly pootergeist
    teckis - take your time and it'll save you time.

  • #3
    New Coder
    Join Date
    Aug 2002
    Location
    Frankfurt/Germany
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    huuu thanks. that was easy. i am very new in PHP+MySQl so i forgott about the LIMIT option... *g* thanks...

  • #4
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,280
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Sorting all the records is probably not the most efficient way. I would use the max function:

    SELECT max(id) FROM TABLE
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #5
    New Coder
    Join Date
    Aug 2002
    Location
    Frankfurt/Germany
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    and how do i get the max value. cause the content of $result is just record #2 or something like that. are there further functions for getting the position value out of the result?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •