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. Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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"; Quote Link to comment 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 Quote Link to comment 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"; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.