Jump to content

How to get rank last month for user id


t_machine

Recommended Posts

I'm wondering if anyone could help with this problem.

I have a table that stores id(autoincrement), userid, date

Each time a vote is casted a new entry is added to the table with the userid and current date. What i am trying to do is get the rank for that user last month by counting the amount of times their user id exists for the last month and comparing that to others for that month.

I can't seem to construct a query for what i need done. Any help would be greatly appreciated.

 

Thanks :)

Link to comment
https://forums.phpfreaks.com/topic/124329-how-to-get-rank-last-month-for-user-id/
Share on other sites

Suggestion, if you use this query a lot you should really create another table that keeps track of monthly votes for each person and maybe some other statistics and use the userid as a primary.

 

Have you attempted anything yet?  If so, can you post it.

Thanks for the reply :)

 

I tried this code so far but I am sure it's on the wrong path

 

  $lastmonth = mktime(0, 0, 0, date("m")-1, date("d"),   date("Y"));
$wsnow1 = date("F,Y", $lastmonth);
$wsdformat = '%M,%Y'; 
  $sql = "SELECT COUNT(id) + 1 AS rank FROM {TOPUSER_TBL} WHERE id>(SELECT * FROM {TOPUSER_TBL} WHERE DATE_FORMAT(FROM_UNIXTIME(date_added), '".$wsdformat."') ='".$wsnow1."' AND userid='$mid') AND DATE_FORMAT(FROM_UNIXTIME(date_added), '".$wsdformat."') ='".$wsnow1."'";

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.