Hello all, im new to this forum, im a noobie, just started coding about 3 weeks ago, don't be too hard on me.
My question is I wan't to check for challenges a user's team posted that have not been excepted after 1 day, then auto refund the user's team back there credits, and then also delete all the challenges. So far here is my code.
//Delete all matches not accepted after 1 day
$arrayin = array();
$autorefund = mysql_query("SELECT * FROM `challenges` WHERE `a` = " . $team['id'] . " "
. "AND `accepted` = 0 AND `completed` = 0 AND `chtype` = 1 AND (`expires` < " . ((int) time()) . ")");
if (mysql_num_rows($autorefund) > 0) {
while ($autorefund = mysql_fetch_assoc($autorefund)) {
$arrayin[] = $autorefund['id'];
mysql_query("UPDATE `teams` SET `balance` = `balance` + " . $autorefund['credits'] . " "
. "WHERE `id` IN (" . mysql_real_escape_string(implode(',', $arrayin)) . ")");
mysql_query("DELETE FROM `challenges` WHERE `a` IN "
. "(" . mysql_real_escape_string(implode(',', $arrayin)) . ") "
. "AND `accepted` = 0 AND `completed` = 0 AND `chtype` = 1 "
. "AND (`expires` < " . ((int) time()) . ")");
}
}
FYI here is the code i had, it works fine, however it will only delete 1 challenge per team, not all of there challenges.
$autorefund = mysql_query("SELECT * FROM `challenges` WHERE `a` = " . $team['id'] . " AND `accepted` = 0 AND `completed` = 0 AND `chtype` = 1 AND (`expires` < ".((int)time()).")");
if (mysql_num_rows($autorefund) > 0) {
while ($autorefund = mysql_fetch_assoc($autorefund)) {
if ($autorefund['accepted'] == 0 and $autorefund['expires'] < time()) {
mysql_query("UPDATE `teams` SET `balance` = `balance` + " . $autorefund['credits'] . " WHERE `id` = " . $team['id'] . "");
mysql_query("DELETE FROM `challenges` WHERE `a` = " . $team['id'] . " AND `accepted` = 0 AND `completed` = 0 AND `chtype` = 1 AND (`expires` < ".((int)time())."));
}
}
}
I inherited this script, its using deprecated statements, i know im not skilled to rewrite the entire site to use prepared statements.