Jump to content

changing my cron into a more clean code


cobusbo

Recommended Posts

Hi I'm trying to run a cron here to

  1. remove profile pictures
  2. delete users
  3. delete private messages
  4. delete messages

 

but I need some help to make my code more clean and effective

<?php
   include("chat_code_header.php");
//// Delete profile pictures and users id older than 30 days////
	$querybd = "SELECT Username, last_online, pprofilepic FROM Users2
WHERE last_online < UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 30 DAY))"; 
	 
$resultbd = mysql_query($querybd) or die(mysql_error());

$users = array();
while($rowbd = mysql_fetch_array($resultbd)){
	if ($rowbd['Username'] != '')
$users[] = $rowbd['Username'];
if($rowbd['pprofilepic'] == ""){}else{
$pprofilepic = realpath($rowbd['pprofilepic']);
print "\n Pictures Removed:\n" . $pprofilepic . "\n";
unlink($pprofilepic);
}
	}
    $list = implode('; ', $users);
if($list == ""){printf ("Nobody Removed\n");}else{
print "\n Users Removed:\n" . $list . "\n";

}

printf("Users Deleted: %d\n", mysql_affected_rows());
   $sqldel = "DELETE Users2, StringyChat, pm, namechanges, kicksamount, broadcast, timeban
FROM Users2
    LEFT JOIN StringyChat ON Users2.mxitid = StringyChat.StringyChat_ip
    LEFT JOIN pm ON Users2.mxitid = pm.mxitid
    LEFT JOIN namechanges ON Users2.mxitid = namechanges.userid
    LEFT JOIN kicksamount ON Users2.mxitid = kicksamount.mxitid
    LEFT JOIN broadcast ON Users2.mxitid = broadcast.mxitid
    LEFT JOIN timeban ON Users2.mxitid = timeban.mxitid
WHERE Users2.last_online < UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 30 DAY))";

mysql_query($sqldel) or die("Error: ".mysql_error());

//// end of removal///
//// removal of messages////
$query = "DELETE FROM StringyChat
WHERE StringyChat_time < UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 7 DAY))"; 
    mysql_query($query);
printf("Messages deleted: %d\n", mysql_affected_rows());

//// removal of private messages////
$query1 = "DELETE FROM pm
WHERE time < UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 7 DAY))"; 
    mysql_query($query1);
printf("Private Messages deleted: %d\n", mysql_affected_rows());


   
?>

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.