HenryC Posted June 5, 2011 Share Posted June 5, 2011 Hello everyone As i said in an earlier post i am making a small sub 4 sub website for our community. I have built 90% of the website and am stuck at the last hurdle, as youtube has a subscription limit of around 30 subscribers an hour i am trying to limit my members to only subing to 30 an hour aswell. The now i have it where on the sub 4 sub page i list all the accounts that can be subed to through a query, and when a member clicks on one of the members to sub to they come off the list for them as they now have them subed and they gain 1 point, i want it where after they have gained 30 points within the hour instead of the query showing the results(members) i can display a message instead telling them to wait the hour and after an hour the results will show again, can anyone help me with this? the query im using to show the members is <?php $query = "SELECT * FROM users WHERE subcreds > 0 AND username NOT IN (SELECT subscriber_username FROM subscribers WHERE my_id = '$id')"; $sql = mysql_query($query) or trigger_error($query . ' has an error:<br />' . mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/238434-limit-records-per-hour/ Share on other sites More sharing options...
revraz Posted June 5, 2011 Share Posted June 5, 2011 You need to enter a timestamp when they sub someone, then you can query all rows within the last hour, compare that result to 30. Quote Link to comment https://forums.phpfreaks.com/topic/238434-limit-records-per-hour/#findComment-1225299 Share on other sites More sharing options...
HenryC Posted June 5, 2011 Author Share Posted June 5, 2011 I do record the current time when they sub someonebut how do i get the posts within the hour as i wouldnt know what hour it is? could you give ma an example. Quote Link to comment https://forums.phpfreaks.com/topic/238434-limit-records-per-hour/#findComment-1225305 Share on other sites More sharing options...
teynon Posted June 5, 2011 Share Posted June 5, 2011 SELECT count(*) FROM USERS WHERE TIMESTAMPCOLUMN > 201106042113 Quote Link to comment https://forums.phpfreaks.com/topic/238434-limit-records-per-hour/#findComment-1225307 Share on other sites More sharing options...
teynon Posted June 5, 2011 Share Posted June 5, 2011 How do you not know what hour it is? date("YmdHis"); Quote Link to comment https://forums.phpfreaks.com/topic/238434-limit-records-per-hour/#findComment-1225308 Share on other sites More sharing options...
HenryC Posted June 5, 2011 Author Share Posted June 5, 2011 <?php $sql = "SELECT * FROM subscribers WHERE username = '$user'"; $result = mysql_query($sql); $row = mysql_fetch_assoc($sql); $time = $row['time']; if ($time ???){ // subed 30 in last hour // show message telling them }else{ // not subed 30 // my code } How can i tell if there has been 30 records within the hour by that user? Quote Link to comment https://forums.phpfreaks.com/topic/238434-limit-records-per-hour/#findComment-1225407 Share on other sites More sharing options...
HenryC Posted June 5, 2011 Author Share Posted June 5, 2011 Ok i have the time of the sub and the current time <?php $sql = mysql_query("SELECT * FROM subscribers WHERE username = '$user'"); $row = mysql_fetch_assoc($sql); $time = $row['time']; // 08:10:04 echo "<br>"; $date = date("H:i:s"); // 08:19:19 What can i use to check if there has been 30 subs within the last hour? Quote Link to comment https://forums.phpfreaks.com/topic/238434-limit-records-per-hour/#findComment-1225424 Share on other sites More sharing options...
teynon Posted June 5, 2011 Share Posted June 5, 2011 <?php $hourAgo=date("H:i:s", mktime(date("H")-1, date("i"), date("s"), date("m"), date("d"), date("Y")); $sql="SELECT count(*) FROM subscribers WHERE `time` > '{$hourAgo}'"; $query=mysql_query($sql); $row=mysql_fetch_assoc($sql); echo "There have been {$row[0]} subs in the last hour."; ?> Quote Link to comment https://forums.phpfreaks.com/topic/238434-limit-records-per-hour/#findComment-1225544 Share on other sites More sharing options...
teynon Posted June 5, 2011 Share Posted June 5, 2011 Or date("H:i:s", strtotime("-1 hour")) Quote Link to comment https://forums.phpfreaks.com/topic/238434-limit-records-per-hour/#findComment-1225545 Share on other sites More sharing options...
HenryC Posted June 7, 2011 Author Share Posted June 7, 2011 Ok i have it working but i want to make sure this is the right way of going about it <?php $id = $_SESSION['id']; $time = time() - 3600; $time = date("H:i:s",$time); $sql = mysql_query("SELECT * FROM subscribers WHERE time > '$time' AND my_id = $id"); $nums = mysql_num_rows($sql); if ($nums > 29){ ?> <center> <font size="3" color="383838"> Your Subscriber Limit Is Up, You May Subscribe Again In 1 Hour</font> </center> <?php }else{ $query = "SELECT * FROM users WHERE subcreds > 0 AND username NOT IN (SELECT subscriber_username FROM subscribers WHERE my_id = '$id') ORDER BY RAND() LIMIT 6"; $sql = mysql_query($query) or trigger_error($query . ' has an error:<br />' . mysql_error()); // show subs so if the user has subed to 30 people then they will get the your subscription limit is up, then after the hour they can sub again that look ok? Quote Link to comment https://forums.phpfreaks.com/topic/238434-limit-records-per-hour/#findComment-1226738 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.