How can I delete all items from a table, EXCEPT for the first x number of records?
So, lets say x = 10 and I have 45 records...how can I delete 11 through 45?
Printable View
How can I delete all items from a table, EXCEPT for the first x number of records?
So, lets say x = 10 and I have 45 records...how can I delete 11 through 45?
Okay, I just realized I misspoke with my problem. What I should have said was:
I almost have it, but it's a some sloppy coding.Quote:
How can I delete all items from a table, EXCEPT for the last x number of records?
Damn...it just took a friend and me almost an hour to figure this out:
And it's so simple...:rolleyes:Code:$total = mysql_num_rows(mysql_query("SELECT * FROM table_name")) - $CONFIG['numitems'];
if ($total > 0) {
$sql = "DELETE FROM table_name LIMIT $total";
mysql_query($sql) or die(mysql_error());
}