dc2007 Posted June 26, 2012 Share Posted June 26, 2012 Hi i have a php mysql query where it see how many attachments users have downloaded per day but i need it to reset at each users midnight but at the moment its no its just removing one each time its 24 hour after. if($row['postdate'] <= (time()-$permissions['ugpindexretention']*24*60*60) AND ($vbulletin->userinfo['userid'] != $row['owner']) AND (!in_array($vbulletin->userinfo['usergroupid'], array(6)))) { standard_error("Sorry you can only download 10 attachments per 24 hours."); } Quote Link to comment https://forums.phpfreaks.com/topic/264811-total-per-day/ Share on other sites More sharing options...
Barand Posted June 26, 2012 Share Posted June 26, 2012 SELECT COUNT(*) FROM downloadlog WHERE owner = $userid AND postdate > NOW() - INTERVAL 24 HOUR If the count is 9 or less it's OK otherwise error message - and no resetting needed Quote Link to comment https://forums.phpfreaks.com/topic/264811-total-per-day/#findComment-1357141 Share on other sites More sharing options...
dc2007 Posted June 26, 2012 Author Share Posted June 26, 2012 thanks for that mate but it was the wrong code lol here the proper one for the download file $grabs= $db->query_first(" SELECT COUNT(*) AS `grab` FROM " . TABLE_PREFIX . "downloaded AS down WHERE down.userid = '" . $vbulletin->userinfo['userid'] . "' AND down.time > NOW() - INTERVAL 24 HOUR "); $vbulletin->db->free_result($grabs); $totgrabs = $grabs['grab']; if($totgrabs >= $permissions['ugpindexperday']) { standard_error("You have reached you daily download limit of 10"); } and for the display of how many the member had downed $perd = $vbulletin->db->query_first(" SELECT COUNT(*) AS `perday` FROM " . TABLE_PREFIX . "downloaded AS down WHERE down.userid = '" . $vbulletin->userinfo['userid'] . "' AND down.time >= NOW() - INTERVAL 24 HOUR "); $vbulletin->db->free_result($perd); $downed = $perd['perday']; but its displaying 0 Quote Link to comment https://forums.phpfreaks.com/topic/264811-total-per-day/#findComment-1357147 Share on other sites More sharing options...
Barand Posted June 26, 2012 Share Posted June 26, 2012 Does it work if you don't free the resultset first? And of course it was the wrong code (I am not a psychic). Just an example. Why second query when you already have "grabs"? Quote Link to comment https://forums.phpfreaks.com/topic/264811-total-per-day/#findComment-1357150 Share on other sites More sharing options...
dc2007 Posted June 26, 2012 Author Share Posted June 26, 2012 no mate still not working Quote Link to comment https://forums.phpfreaks.com/topic/264811-total-per-day/#findComment-1357152 Share on other sites More sharing options...
Barand Posted June 26, 2012 Share Posted June 26, 2012 is down.time a DATETIME column? Quote Link to comment https://forums.phpfreaks.com/topic/264811-total-per-day/#findComment-1357170 Share on other sites More sharing options...
dc2007 Posted June 26, 2012 Author Share Posted June 26, 2012 time int(10) UNSIGNED No Quote Link to comment https://forums.phpfreaks.com/topic/264811-total-per-day/#findComment-1357171 Share on other sites More sharing options...
Barand Posted June 26, 2012 Share Posted June 26, 2012 try substituting FROM_UNIXTIME(down.time) Quote Link to comment https://forums.phpfreaks.com/topic/264811-total-per-day/#findComment-1357188 Share on other sites More sharing options...
dc2007 Posted June 26, 2012 Author Share Posted June 26, 2012 your a legend mate sorted AND FROM_UNIXTIME(down.time) > NOW() - INTERVAL 24 HOUR thank you. maybe you could have a look at my other issue http://forums.phpfreaks.com/index.php?topic=361603.0 thanks again.. Quote Link to comment https://forums.phpfreaks.com/topic/264811-total-per-day/#findComment-1357198 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.