[SOLVED] please how to find last row

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
lazerbri
Forum Newbie
Posts: 15
Joined: Sat Dec 27, 2003 8:17 am

please how to find last row

Post by lazerbri »

I can find the Id number of last entry with
$iD=mysql_insert_id();

but need to get the last number with out adding any new record

Its prob very easy but I can't find it can you help

thanks brian
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

Code: Select all

select max(`name_of_the_field`) from `name_of_the_table`;
User avatar
lazerbri
Forum Newbie
Posts: 15
Joined: Sat Dec 27, 2003 8:17 am

thank you so much

Post by lazerbri »

thanks for the fast responce it works I could'nt move ahead with out it
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

why not simple

$sql = "SELECT * FROM table_name ORDER by DESC LIMIT 1";
User avatar
lazerbri
Forum Newbie
Posts: 15
Joined: Sat Dec 27, 2003 8:17 am

thanks this looks good to

Post by lazerbri »

I will try using this but con't quit under stand what DESC LIMIT 1 is
but will look on google to learn about it thanks
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

he meant:

Code: Select all

SELECT * FROM `table_name` ORDER BY `some_field` DESC LIMIT 1
...sort by 'some_field' in descending order.
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

oops

thanks for clarifying that feyd. 8)
Post Reply