简体   繁体   中英

Get last row name by column, then DESC

I need to get the last username registered in my members table. The last registered has the highest ID number.

At the moment, I can get the highest ID with this code, but I need to get the lowest.

$resultlatestuser = mysql_query("SELECT * from $tbl_name ORDER BY 'id' DESC LIMIT 0,1;"); $row = mysql_fetch_row($resultlatestuser); echo $row[1];

This echos the ID as john, but john has the lowest ID: 1.

This is what my database looks like, for example I need Dayancbro echo'd because he has the highest ID.

http://puu.sh/2k4Hh

  • James

是时候使用聚合函数了:

SELECT MAX(id) FROM $tablename

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM