Wallpapers Forums Login

Get Last Mysql Row From Database Retrieve Last Entry ID From Table

today i wanted to get the last entry of a database.

for example, i had a table with user names and each user had a user_id field, this field was incrementing so each user_id was unique. so as new users signed up, a new user_id was created but i wanted a way to get the last user_id for a script i was writing so this is the way i found out on using php to search and getting the id of the last inserted row in mysql through php.

you can use this query to get the results you want with this sql query i created to use as en example:

code:
$sql = "SELECT user_id FROM my_users_table ORDER BY user_id DESC LIMIT 0,1";


this will retrieve the last entry on your database and you can use it or display it on your script.
xvader Sat May 19, 2012
hello, i've tried this code by typing:

<?php $lastvalue = mysql_query('SE ID FROM SomeTable ORDER BY ID DESC LIMIT 0,1';); PRINT '$lastvalue'; ?>

but, the printed result is: $lastvalue

not the last ID i wish to print. need help, thank you :)
tinkoo Sun May 13, 2012
ooo bhen chood k bacho tuadi maaan ki choot
Pinna Mon Jan 09, 2012
Nice I was searching same for that.
kidane Tue Jan 03, 2012
thanks its help us ........post other logic regarding DB since DB best of storage
Sushil Wed Nov 30, 2011
in my case always print Resource ID#6

need your help guys, please mail me your suggestion at sushil553sim - at - gm
brindha Mon Sep 19, 2011
hi

it's work great thank you so much dear.
xcoderx Sat Aug 06, 2011
this helped me thanks soo much
Dolly Fri Jan 21, 2011
Thank u!! Very Helpful I was trying to figure out the same problem :)
Ralph Sun Aug 01, 2010
Nice this limit solution, but I have a group situation where the last record from a joined table (1->n) has to be returned. This is not a solution for that.
Asanka Tue Jun 22, 2010
$sql = "SELECT max(user_id) FROM my_users_table";
Asanka Tue Jun 22, 2010
i think this one is better

$sql = "SELECT max(user_id) FROM my_users_table
cHRIS Mon May 31, 2010
You are a genius! thank you very much. spent a whole day trying fix my problem!!
better Wed Apr 28, 2010
Your method is quite slow.
It is easier to use SELECT LAST_INSERT_ID();
instead ;)
Denis Thu Apr 15, 2010
Hy..

i have almost the same problem.. but i just will retrieve all rows except last 3 rows.. how can i resolve this problem :o
john Sat Feb 06, 2010
I had the exact same problem. Thanks for posting this!

Related Content

Information

Share

wallpaperama | Wallpapers | Forums | Terms Of Service

copyright © 2013 wallpaperama - All Rights Reserved - Last Updated Mon May 06, 2013 (-8 GMT)
Powered by: Webune Forums V5