...

View Full Version : finding record with the highest ID



Chris Hunter
11-07-2002, 11:16 AM
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?

Íkii
11-07-2002, 11:23 AM
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");

Chris Hunter
11-07-2002, 11:26 AM
huuu thanks. that was easy. i am very new in PHP+MySQl so i forgott about the LIMIT option... *g* thanks...

Spookster
11-07-2002, 02:25 PM
Sorting all the records is probably not the most efficient way. I would use the max function:

SELECT max(id) FROM TABLE

Chris Hunter
11-07-2002, 02:29 PM
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?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum