unsider Posted March 9, 2008 Share Posted March 9, 2008 I am trying to add a feature to my website, and I'm curious how you would select the last entry or last id from your DB table and output the $username. I will be checking this again soon, but I've gotta go, and would like to work on it when I get back. Thanks. Link to comment https://forums.phpfreaks.com/topic/95161-latest-member-in-db/ Share on other sites More sharing options...
pocobueno1388 Posted March 9, 2008 Share Posted March 9, 2008 I'm assuming you have an auto-incrementing ID field in the table, so you would do a query like this: SELECT username FROM users ORDER BY ID DESC LIMIT 1 Link to comment https://forums.phpfreaks.com/topic/95161-latest-member-in-db/#findComment-487433 Share on other sites More sharing options...
Xajel Posted March 9, 2008 Share Posted March 9, 2008 like above, but if you have registration date/time or timestamp you can use it too, so ID or registration date, just sort them from up to down ( DESC ) and LIMIT 1 Link to comment https://forums.phpfreaks.com/topic/95161-latest-member-in-db/#findComment-487447 Share on other sites More sharing options...
unsider Posted March 9, 2008 Author Share Posted March 9, 2008 I have a timestamp set up for my users, so I'll go ahead and use that. Correct? $query = "SELECT 'username' FROM 'users' ORDER BY TIMESTAMP DESC LIMIT 1"; echo "$query"; Link to comment https://forums.phpfreaks.com/topic/95161-latest-member-in-db/#findComment-487451 Share on other sites More sharing options...
Xajel Posted March 9, 2008 Share Posted March 9, 2008 well every type of usage will have have it's features, using ID will force sorting the users by exactly when they registred, wether they changed the registration date or not, but using timestamp will give you this option... yep, it's okay, but if go to errors then you can echo the query into the HTML page and paste it into phpmyadmin, it will give you the error if there's any one Link to comment https://forums.phpfreaks.com/topic/95161-latest-member-in-db/#findComment-487455 Share on other sites More sharing options...
unsider Posted March 9, 2008 Author Share Posted March 9, 2008 I should probably post the correct coding if anyone stumbles upon this later. $query = "SELECT username FROM users ORDER BY TIMESTAMP DESC LIMIT 1"; $result = mysql_query($query) or die('Error, query failed'); echo "$result"; Link to comment https://forums.phpfreaks.com/topic/95161-latest-member-in-db/#findComment-487460 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.