Jump to content

Limit Records Per Hour


HenryC

Recommended Posts

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());

Link to comment
Share on other sites

<?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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.