...

View Full Version : time since last submissions



Chris-2k
01-09-2012, 11:33 PM
hi

here is my whole submit function; http://pastebin.com/qdCGV4kD

i wanna add a "time since last submit" feature to this bit:


// 24 hour mod start, rewritten and optimized by Chris.
//Get time and call for last 24 hr time stamp.
$Time = time();
$Day = (60*60*24);
$Time = ($Time - $Day);

$Site = mysql_real_escape_string($_POST['sname']);

//Lookup site and get its ID for next 2 queries
$querySite = ("SELECT * FROM wcddl_sites WHERE name='$Site'");
$resultSite = mysql_query($querySite);
$rowSite = mysql_fetch_array($resultSite);

//Get number of downloads already stored within last 24hrs
$queryDownloads = ("SELECT * FROM wcddl_downloads WHERE sid='$rowSite[id]' and dat > '$Time'");
$resultDownloads = mysql_query($queryDownloads);
$countDownloads = mysql_num_rows($resultDownloads);

//Get number of downloads in queue already stored within last 24hrs
$queryQueue = ("SELECT * FROM wcddl_queue WHERE sid='$rowSite[id]'");
$resultQueue = mysql_query($queryQueue);

if (!$countQueue = mysql_num_rows($resultQueue)) {
//If nothing in queue and mysql_num_rows returns false, set to 0
$countQueue = 0;
}

//Get total count of everything submitted in last 24 hrs (inc queued items that have been submitted anytime)

$totalCount = ($countQueue + $countDownloads);

for($i=0;$i<=count($titles)-1;$i++) { // loop thru the input fields
if(!$this->allow_dupes) { // check for dupe titles or urls
unset($downDupe);
$downDupe = mysql_query("SELECT COUNT(*) FROM wcddl_downloads WHERE url = '".mysql_real_escape_string($urls[$i])."'");
$downDupe = mysql_result($downDupe,0);
if($downDupe < 1)
unset($downDupe);
} // dupe check end

//Check each row of fields is set
if(!empty($titles[$i]) && !empty($urls[$i]) && !empty($types[$i]) && (in_array(strtolower($types[$i]),$this->allowed_types) || in_array($types[$i],$this->allowed_types)) && !isset($downDupe)) {

//If total submitted items more than allowed.
if ($totalCount >= $this->Limit) {
//Print error, break out and process no more
$this->Output = '<center><div class="error_message">You can not submit any more downloads as you have reached your daily limit.</div></center>';
break;
}

//All set so insert details.
mysql_query("INSERT INTO wcddl_queue (sid,title,type,url) VALUES ('".mysql_real_escape_string($sid)."','".mysql_real_escape_string($titles[$i])."','".mysql_real_escape_string($types[$i])."','".mysql_real_escape_string($urls[$i])."')");

$totalCount++;

$amountLeft = ($this->Limit - $totalCount);
$this->Output = '<center><div class="success_message">'.$totalCount.' downloads were successfully submitted in the last 24 hours!<br>
You have '.$amountLeft.' of '.$this->Limit.' submissions left.</div></center>';
// 24 hour mod end, rewritten and optimized by Chris.

thats my limit mod, i havee time fields in the queue n downloads table......

mlseim
01-10-2012, 02:13 AM
All I see on your pastebin is a "survey" box.

Do you have a column in your database table where you can store a timestamp?
Simply the time() value whenever they update the table.

$timestamp=time();

Then update that column in the table.

Chris-2k
01-10-2012, 03:44 PM
srry bwt tht

yea i ave timestap fields in DB, i need to store te tiimes so the user sees each time when they sbmit + the need to end when they reacch 24 hrs

Dormilich
01-10-2012, 04:03 PM
Do you have a column in your database table where you can store a timestamp?
Simply the time() value whenever they update the table.

$timestamp=time();

Then update that column in the table.

for the more advanced SQL users, there is the possibility to make the DB track those times itself. for an INSERT query just define a default value (e.g. CURRENT_TIMESTAMP) then the current time is automatically assigned. for an UPDATE query it would probably be best to use a trigger.

Chris-2k
01-10-2012, 09:17 PM
so can any1 hellp me?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum