Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-07-2002, 11:16 AM   PM User | #1
Chris Hunter
New Coder

 
Join Date: Aug 2002
Location: Frankfurt/Germany
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Chris Hunter is an unknown quantity at this point
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?
Chris Hunter is offline   Reply With Quote
Old 11-07-2002, 11:23 AM   PM User | #2
Ökii
Regular Coder

 
Join Date: Jun 2002
Location: UK
Posts: 577
Thanks: 0
Thanked 0 Times in 0 Posts
Ökii is an unknown quantity at this point
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.
Ökii is offline   Reply With Quote
Old 11-07-2002, 11:26 AM   PM User | #3
Chris Hunter
New Coder

 
Join Date: Aug 2002
Location: Frankfurt/Germany
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Chris Hunter is an unknown quantity at this point
huuu thanks. that was easy. i am very new in PHP+MySQl so i forgott about the LIMIT option... *g* thanks...
Chris Hunter is offline   Reply With Quote
Old 11-07-2002, 02:25 PM   PM User | #4
Spookster
Supreme Overlord


 
Spookster's Avatar
 
Join Date: May 2002
Location: Marion, IA USA
Posts: 6,234
Thanks: 4
Thanked 81 Times in 80 Posts
Spookster will become famous soon enough
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
Who gave you that Ugging infraction? Yeah that's right it was me!
Spookster is offline   Reply With Quote
Old 11-07-2002, 02:29 PM   PM User | #5
Chris Hunter
New Coder

 
Join Date: Aug 2002
Location: Frankfurt/Germany
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Chris Hunter is an unknown quantity at this point
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?
Chris Hunter is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:11 PM.


Advertisement
Log in to turn off these ads.