Jump to content

How do i Do Last user from mysql table?


Gayner

Recommended Posts

please do not use oni-kuns method and I will tell you why. Say you have 20 users in the database but maybe some of the other users were deleted leaving there id blank this would fail. The reason is say you had 25 registered but 5 were removed. the last id would be 25. Now if you used the method that oni-kun suggests it would select the count (or 20 in this case) as the id which would not be the correct id. Also that id might not even exist if it was one that was deleted.

Link to comment
Share on other sites

if you are using an autoincrement id you could do:

 

$query = "SELECT * FROM users ORDER BY id DESC LIMIT 1";

 

The reason I did that is by doing it DESC you will get the last user and it will only return 1 result that way it doesnt go through all the users.

 

sweet thank u

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.