$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++;
}
Looks good to me. Another way to do it would be to calculate the timestamp in php rather than having MySQL do it, but in this case I don't see that their would be anything to gain either way.
I would think that having MySQL do the conversion is faster than having PHP do it, even if it is only .000000000001 of a second. I could be wrong but that's the reason I do it.