cobusbo Posted March 12, 2016 Share Posted March 12, 2016 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()); ?> Quote Link to comment https://forums.phpfreaks.com/topic/300986-changing-my-cron-into-a-more-clean-code/ Share on other sites More sharing options...
ginerjm Posted March 12, 2016 Share Posted March 12, 2016 First thing would be to rewrite using mysqlI or PDO interface. Once again (for the benefit of all) MYSQL is deprecated and has been for years. That means Stop Using It. Quote Link to comment https://forums.phpfreaks.com/topic/300986-changing-my-cron-into-a-more-clean-code/#findComment-1531943 Share on other sites More sharing options...
benanamen Posted March 12, 2016 Share Posted March 12, 2016 Here is a link to a good PDO tutorial. Once you update your code to current coding standards we will be happy to help you if you get stuck. At this point in coding time, nobody should be helping you get obsolete code working. Shame on them if they do. https://phpdelusions.net/pdo Quote Link to comment https://forums.phpfreaks.com/topic/300986-changing-my-cron-into-a-more-clean-code/#findComment-1531945 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.