uploader of the month cleanup

Started by redworm, August 01, 2011, 02:55:25 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

putyn

this would be a proper way of doing it
Code (php) Select

$last_update = file_get_contents('cache/numero_uploads_mes.txt');

if(date('j') == 1 && ($last_update+86400) > time() ) {
  $insert = array();
  $month  = date('F');
  $year   = date('Y');
  $res = mysql_query('SELECT username,numero_uploads_mes FROM users WHERE numero_uploads_mes > 0 ORDER BY numero_uploads_mes DESC') or sqlerr(__FILE__,__LINE__);
    while($arr = mysql_fetch_assoc($res))
      $insert[] = sprintf('(\'%s\',\'%s\',\'%s\',%d)',$arr['username'],$month,$year,$arr['numero_uploads_mes']);
  if(count($insert))
    mysql_query('INSERT INTO topmes (nome, mes, ano, numero_upload_mes) VALUES '.join(', ',$insert)) or sqlerr(__FILE__,__LINE__);
  mysql_query('UPDATE users SET numero_uploads_mes = 0 WHERE numero_uploads_mes > 0') or sqlerr(__FILE__,__LINE__);
  file_put_contents('cache/numero_uploads_mes.txt',time());
}


note the code was written of the top of my head - probably will not work without some testing
also - i see you dont save the userid, just the username - if your displaying the data stored in topmes and you display the username and a link to profile - and use the username to find the userid - your using too many queries for nothing

also if you save you dates as text (2007-12-15 23:50:26) you can use the mysql month() function and the mysql year() function to extract the month and the year from your date

anyway hope this helps you

redworm

hello

I need that the code in day 1 of each month e just one time in that day , go get the name , mumber_uploads_month to the users table ,ordered by biggest mumber_uploads_month after that put the data name,month ,mumber_uploads_month in other table and for last that mane a reset to mumber_uploads_month to 0 in all users

i made other code but i dont now if works lol
here the code

  // ===clear uploader do mes by redworm
$dia = date("d");
$checkUploadsStatus = "SELECT UploadCounterStatus FROM topnomes_status";
$checkUploadCounterStatus = mysql_query($checkUploadsStatus);
while ($row = mysql_fetch_assoc($checkUploadCounterStatus)) { $checkNumeroUploadsStatus = $row["UploadCounterStatus"]; }

if ($dia == "01" && $checkNumeroUploadsStatus == "1") {
$getlist = sql_query("SELECT username, numero_uploads_mes FROM users ORDER BY numero_uploads_mes DESC LIMIT 1") or sqlerr(__FILE__, __LINE__);
$arrr = mysql_fetch_assoc($getlist);
mysql_query("INSERT INTO topmes (nome, mes, ano, numero_upload_mes)
VALUES (%s, %s, %s)", sqlesc($arrr['username']), sqlesc(date("F")), sqlesc(date("Y")), sqlesc($arrr['numero_uploads_mes'])) or sqlerr(__FILE__, __LINE__);
mysql_query("UPDATE users SET numero_uploads_mes = 0") or sqlerr(__FILE__, __LINE__);
write_log("Clean ao uploader do mes: {$arrr['username']} ganhou no des de $mes");

mysql_query("UPDATE topnomes_status SET UploadCounterStatus = '0'");
}

if ($dia == "02" && $checkNumeroUploadsStatus == "0") { mysql_query("UPDATE topnomes_status SET UploadCounterStatus = '1'"); }
// ===end


what you think?

sorry my bad english :p

putyn

the check its correct but my not so sure about the code inside the if statement , your missing some sprintf and a while also doing queries inside a while its a bad practice
tell me what the code should do i may be able to write something for you

redworm

hi guys
I'm trying to get a code for the cleanup and I wanted to run only one time every day 1 of each month but i dont now how do that

here my code

// ===clear uploader do mes
$dia = date("d");
$mes = date("F");
$horas = date("H:i:s");
if ($dia == "01"){
$get = sql_query("SELECT name, numero_uploads_mes FROM users ORDER BY numero_uploads_mes DESC LIMIT 1") or sqlerr(__FILE__, __LINE__);
$arrr = mysql_fetch_assoc($get);
mysql_query("INSERT INTO topmes (nome, mes, numero_upload_mes) VALUES (%s, %s, %s)", sqlesc($arrr['name']), sqlesc(date("F")), sqlesc($arrr['numero_uploads_mes'])) or sqlerr(__FILE__, __LINE__);
mysql_query("UPDATE users SET numero_uploads_mes = 0") or sqlerr(__FILE__, __LINE__);
write_log("Clean ao uploader do mes: {$arrr['username']} ganhou no des de $mes");
}
// ===end


someone can help?

thanks in advance