Jump to content

Manual stats of users


matfish

Recommended Posts

Hi, I was wondering if anyone could help me with the following:

 

* Got a table of members and trying to get the last user who registered. Would this be the last userID as this is an auto_increment or I do have a registered field which is a timestamp but how to find the latest date?

 

* I want to find the member who has posted the most comments? Dont know where to start with this one. How would you like distinct the usernames in the comments table and bring back the highest count?

 

Any help would be appreciated.

 

Thanks

Link to comment
Share on other sites

Got a table of members and trying to get the last user who registered. Would this be the last userID as this is an auto_increment or I do have a registered field which is a timestamp but how to find the latest date?

Just use userID since the latest user will have the highest id if it is auto incrementing.

SELECT * FROM users ORDER BY userID DESC LIMIT 1;

 

I want to find the member who has posted the most comments? Dont know where to start with this one. How would you like distinct the usernames in the comments table and bring back the highest count?

I'd just increment a field called something like num_comments in the users database each time a user comments. Decrement it if you delete a comment. Then just do this:

SELECT * FROM users ORDER BY num_comments DESC LIMIT 1;

Link to comment
Share on other sites

I would add in some sort of "start date" in the users table that you can query off of. This can also be helpful later on down the road too for other things.

 

for the count you can do something like:

 

SELECT userid, count(userid) as total FROM comments ORDER BY total DESC LIMIT 1

Link to comment
Share on other sites

Hey, thanks for the replies.

 

Daniel0's suggestions work - thank you, but didnt fancy a table just to increment a number. I will do this suggestion if I get stuck.

 

I do have a registered date (timestamp) - is it the same thing as order by registered_date DESC LIMIT 1? Just implemeting the userID thingy...

 

Thanks again

 

Link to comment
Share on other sites

Hey, thanks for the replies.

 

Daniel0's suggestions work - thank you, but didnt fancy a table just to increment a number. I will do this suggestion if I get stuck.

 

I do have a registered date (timestamp) - is it the same thing as order by registered_date DESC LIMIT 1? Just implemeting the userID thingy...

 

Thanks again

 

 

Yes the register_date will work just as well.

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.