简体   繁体   中英

How to get last login ip from database

I want to get last login ip according to my data.

Example my current data

----------------------------------------
id uid  ip            date
-----------------------------------------
1  3    192.168.1.1   2010-11-22 22:25:39
2  3    192.168.1.8   2010-11-23 22:28:12
3  3    192.168.1.3   2010-11-24 00:01:30
4  3    192.168.1.5   2010-11-25 00:20:25

How to get the id 3 as the last login ip?

$select = "SELECT * FROM ip_address WHERE uid='3'";

Try:

select ip from ip_address order by date desc limit 0,1;

...Will return the last IP.

select * from ip_address order by date desc limit 0,1;

...Will return the whole record.

SELECT * FROM `ip_address` ORDER BY `date` DESC LIMIT 0,1

EDIT: there should be back ticks on at least date, preferably ip_address too.

EDIT 2: There we go.

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