How Can Get The Last Registered User Name ?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
saqib389
Forum Commoner
Posts: 44
Joined: Wed Nov 30, 2005 2:13 am

How Can Get The Last Registered User Name ?

Post by saqib389 »

how can i get the last registered users name....

for example

Last Sign Up User
ABC


Wat should be the code ?
i m sorry for asking these kind of question.. actually i m new. :(
sheila
Forum Commoner
Posts: 98
Joined: Mon Sep 05, 2005 9:52 pm
Location: Texas

Post by sheila »

If each record has a timestamp field to note when it was created, then you need to run a query and find out which has the latest 'created' date. Can't offer any more help without seeing the structure of your table.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Do you store your registered users in a database? Do you store the date and time that they registered?

Mac
saqib389
Forum Commoner
Posts: 44
Joined: Wed Nov 30, 2005 2:13 am

Post by saqib389 »

yes i store in database


table users------

Code: Select all

CREATE TABLE users ( 
  userid int(25) NOT NULL auto_increment, 
  first_name varchar(25) NOT NULL default '', 
  last_name varchar(25) NOT NULL default '', 
  email_address varchar(255) NOT NULL default '', 
  username varchar(25) NOT NULL default '', 
  password varchar(255) NOT NULL default '', 
  info text NOT NULL, 
  signup_date datetime NOT NULL default '0000-00-00 00:00:00', 
  activated enum('0','1') default NULL, 
  decrypted_password varchar(255) NOT NULL default '', 
  PRIMARY KEY  (userid), 
  UNIQUE KEY username (username) 
) TYPE=MyISAM COMMENT=' Membership Information';
here is the info of my table
what shuld b the code to get the last registered user name ?
mickd
Forum Contributor
Posts: 397
Joined: Tue Jun 21, 2005 9:05 am
Location: Australia

Post by mickd »

well, one can assume that the highest userid would be the most recent signup...

a query something like this:

*UNTESTED*

Code: Select all

SELECT max(userid) as lastregistered FROM users
pilau
Forum Regular
Posts: 594
Joined: Sat Jul 09, 2005 10:22 am
Location: Israel

Post by pilau »

mickd wrote:well, one can assume that the highest userid would be the most recent signup...
Yeah this is exactly what I thought of doing. But if you have a timestamp record on your users table it's much better to my opinion. More fail-safe, and more accurate.
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post by neophyte »

Assuming you are using MYSQL and you you just performed an insert on the table you can find out the last inserted id with mysql_insert_id.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

mysql_last_insert_id() only returns the id of the last inserted record for that connection :)
saqib389
Forum Commoner
Posts: 44
Joined: Wed Nov 30, 2005 2:13 am

Post by saqib389 »

what would b the query ?
or code for getting this ?
i m confused..! :?
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

If you don't keep a datetime or (autoincrement) identifier it's impossible to find out.. As soon as you have that, you can SELECT MAX(column) FROM table.. Nothing confusing about it.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Code: Select all

select username from users_table where time_registered = max(time_registered) limit 1
User avatar
spamyboy
Forum Contributor
Posts: 266
Joined: Sun Nov 06, 2005 11:29 am
Location: Lithuania, vilnius

Post by spamyboy »

useful
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

oorrr...

Code: Select all

SELECT `username` from `users` ORDER BY `userid` DESC LIMIT 1
Post Reply