MySQL question about delete code
Posted: Thu Jul 27, 2006 7:26 pm
What this code does is find all entries that are older than $retention.
It works, but I was wondering it this is done correctly.
It works, but I was wondering it this is done correctly.
Code: Select all
$sql = "SELECT ID FROM bin
WHERE (UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(date)) / 3600 / 24 > {$retention} {$gr}";
$res = mysql_query($sql);
echo "Deleting ".mysql_num_rows($res)." from bin\n";
while($arr = mysql_fetch_assoc($res)) {
$sql = "DELETE FROM parts WHERE binID = {$arr['ID']}";
mysql_query($sql);
$sql = "DELETE FROM bin WHERE ID = {$arr['ID']}";
mysql_query($sql);
$count++;
}