t_machine Posted September 15, 2008 Share Posted September 15, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/124329-how-to-get-rank-last-month-for-user-id/ Share on other sites More sharing options...
Maq Posted September 15, 2008 Share Posted September 15, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/124329-how-to-get-rank-last-month-for-user-id/#findComment-642047 Share on other sites More sharing options...
t_machine Posted September 15, 2008 Author Share Posted September 15, 2008 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."'"; Quote Link to comment https://forums.phpfreaks.com/topic/124329-how-to-get-rank-last-month-for-user-id/#findComment-642056 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.