finding the newest id in the database efficiently

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
robster
Forum Contributor
Posts: 360
Joined: Wed Jul 16, 2003 8:28 am
Location: Sunshine Coast, Australia

finding the newest id in the database efficiently

Post by robster »

Hi all,

I have a function that adds a client to the database. Then, I want to extract that clients ID from mysql (using php). I want this the moment after the client has been added.

What is the most efficient way to do this? Currently I am parsing through the WHOLE database, taking the ID, then when I get to the last client, I have the latest ID. It's aweful ;)

Any suggestions appreciated.

Rob
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

User avatar
robster
Forum Contributor
Posts: 360
Joined: Wed Jul 16, 2003 8:28 am
Location: Sunshine Coast, Australia

Post by robster »

amazing! I'm going through this 'all excited about learning' stage and this whole php/mysql thing is really making sense to me now.

This function (and its implimentation) is a great example of elegance over my clutzy learning stage that I'm pulling out of.

Thanks so much for that link.


rob
Post Reply