Results 1 to 3 of 3

Thread: [Resolved] "DELETE FROM" Question

  1. #1

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    [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.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  2. #2

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    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.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  3. #3

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    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...
    My evil laugh has a squeak in it.

    kristopherwilson.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width