Jump to content

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."'";

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.