SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict brain's Avatar
    Join Date
    Sep 2001
    Location
    Amsterdam
    Posts
    249
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how to remove oldest field after maximum fields ?

    Members of my site have a personal guestbook. I want to give them space for 100 comments. How can I achieve that if item 101 is posted, the oldest is being removed so that 100 items stay in the db ?

    the mySQL table PersonalGuestbook:
    pgID
    pgName
    pgComment
    pgOwner

  2. #2
    pie??? PIE!!!! rsdl's Avatar
    Join Date
    May 2001
    Location
    Vancouver, BC Canada
    Posts
    502
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what i'd do is add an if condition saying that if total rows are > 100 then delete the earliest comment. this can be achieved by
    $sql = mysql_query("SELECT * FROM PersonalGuestbook ORDER BY pgID ASC")
    $id = mysql_fetch_array($sql);
    $id = $id['pgID'];

    $sqltwo = mysql_query("DELETE FROM PersonalGuestbook WHERE pgID='$id'")


    and then just use the delete function to delete as many entries nessecary to revert back to 100 comments.

    -rsdl


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
  •