SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2001
    Location
    uk
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Restrict Db to last 50 records...

    Here's what I'm looking to do....

    I have data in mysql but I want to delete the oldest record when the number of records equals 50...

    If the database is emptied by me, I want it to build back up to 50 records and then begin the deletion of the oldest record again once this happens.

    How can I achieve this?

    Adding the records is no problem...

    TIA

    Caunton

  2. #2
    SitePoint Enthusiast
    Join Date
    Jan 2002
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Everytime a record is added, couldn't you do a query of the database loading say one field into an array. Then, using the count function, detect whether the number of elements is greater than 50. If not, simply ignore it and close the database connection. If it is greater than fifty, use a loop and remove all "extra" records.

    Just a suggestion,
    Shawn

  3. #3
    That's Right. notepad_coder's Avatar
    Join Date
    Apr 2002
    Location
    Colorado
    Posts
    835
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can do something like this if the number is in an INT row
    PHP Code:
    $d mysql_query("DELETE FROM table WHERE num_row > 50");
    // or
    $d mtsql_query("DELETE FROM table WHERE num_row = 50"); 
    - the lid is off the maple syrup again!

  4. #4
    SitePoint Enthusiast
    Join Date
    Apr 2001
    Location
    uk
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up

    Thank you to you both....

    I have used the count() coding and then use a if > 50 to delete the data...This is working perfectly but now I have another query which I will post in a seperate topic soon.

    Thanks again

    Caunton


Bookmarks

Posting Permissions

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