Hi I'm trying to run a cron here to
remove profile pictures delete users delete private messages 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());
?>