|
-
May 20th, 2003, 06:16 PM
#1
Thread Starter
Stuck in the 80s
[Resolved] "DELETE FROM" Question
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?
Last edited by The Hobo; May 20th, 2003 at 10:28 PM.
-
May 20th, 2003, 09:55 PM
#2
Thread Starter
Stuck in the 80s
Okay, I just realized I misspoke with my problem. What I should have said was:
How can I delete all items from a table, EXCEPT for the last x number of records?
I almost have it, but it's a some sloppy coding.
Last edited by The Hobo; May 20th, 2003 at 10:11 PM.
-
May 20th, 2003, 10:27 PM
#3
Thread Starter
Stuck in the 80s
Damn...it just took a friend and me almost an hour to figure this out:
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());
}
And it's so simple...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|