02-16-2010, 04:08 PM
|
#1 (permalink)
|
|
The Acquainted
Join Date: Feb 2008
Posts: 107
Thanks: 3
|
Delete rows except last added 250 ones
Hello mates,
I want to delete all rows in a table except last added 250 ones. I have this script, but it deletes all rows except first 250 ones. I need your help, thanks.
PHP Code:
$query="SELECT * FROM looks";
$result=mysql_query($query);
echo mysql_error();
$all_looks = array();
for($i=0; $i<mysql_num_rows($result); $i++){
$row = mysql_fetch_array($result);
$all_looks[$i] = $row["id"];
}
for($i=0; $i<count($all_looks)-251; $i++){
mysql_query("DELETE FROM looks WHERE id='".$all_looks[$i]."';");
}
echo mysql_error();
|
|
|