Forum Moderators: coopster
<?php$conn = mysql_connect("host", "user", "pass") or die(mysql_error());
mysql_select_db("db", $conn) or die(mysql_error());
$result = mysql_query("SELECT id FROM table ORDER BY id") or die(mysql_error());
$num = mysql_num_rows($result);if($num > 500)
{
for($i = $num - 500; $i >= 0; $i--)
{
$answer = mysql_fetch_array($result)
$ids_to_delete .= $answer["id"].",";//they are sorted by creation - the oldest are the first
}$ids_to_delete = substr($ids_to_delete, 0, -1);// get rid of the last comma
if(mysql_query("DELETE FROM table WHERE id IN ($ids_to_delete)")) echo "Deletion successful!";
else die(mysql_error());
}?>
I hope this cleares it a little
Best regards
Michal Cibor