PHP and Mysql, getting the last row in a table

They have: 141 posts

Joined: Aug 1999

Is there any simple ways to pull out the last row in a table. (I want the largest 'Primary Key'). I was wondering if there were any mysql functions to automaticly select the last row in a table.

Thanks

------------------
Visit the dLo.Network
http://dlo.net

They have: 5,633 posts

Joined: Jan 1970

Hi Randall,

I have been looking for the same thing - but, I have never found a command that will do it. I have just worked around it. It depends on what you need the last row for and what you plan to do with the information on the row.

PHP does have a command that allows you to get the results of the last query that may help if you insert the last row right before needing to use it. Don't know if that will work or not.

I really would like to know if there is some type of function, whether it be of mySQL or PHP, that will take care of this as well... If anyone has the secret, please share!

------------------
TWF Administrator

Looking for Web Hosting Services?
Dynamic Internet Solutions : http://www.dids.com
Windows NT and UNIX Hosting ($9.95 - $399.95), Dedicated Servers, and Co-Location Programs

They have: 66 posts

Joined: May 1999

As far as selecting the last row, why not make an id column:

code:

id int not null auto_increment, primary key(id)[/code]

Anq use this to select:
 
code:
select * from tablename order by id desc limit 1[/code]

That should select the last row of the table.

------------------
-Blur

[This message has been edited by Blur (edited 06 April 2000).] 

Ed Aronyk (Blur)
Divergent Digital Media

The secret of success is sincerity. Once you can fake that, you've got it made.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.