Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder Troy297's Avatar
    Join Date
    Oct 2006
    Location
    Earth
    Posts
    314
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Post "Auto-Expire" DB Entries?

    Hi,

    I am currently in the process of redoing a DJ Panel script that I created and am looking into sending out "IP Alerts" to users... what it does is stores the ip and message to the user in the db until the users ip matches the one in the db, then it gives them a javascript popup with the message and then deletes the db entry....

    What I was wondering is if I could somehow make it so the entry in the db would show a popup to every user that visits the site in the next 5 minutes and then delete itself after say 5 minutes?

    My current syntax is below:
    PHP Code:
    <?php
    require('connect.php');
    $ipaddr $_SERVER['REMOTE_ADDR'];
    $result mysql_query("SELECT id, toip, message, fromdj FROM rp_alerts ORDER BY id ASC") or die(mysql_error());
    $row mysql_fetch_array($result);
    if(
    $ipaddr == $row['toip']) {
    echo 
    '<script language="JavaScript" type="text/javascript">
    alert("DJ '
    .$row['fromdj'].' Says: '.$row['message'].'")</script>';
    }
    ?>
    <?php
    $result 
    mysql_query("DELETE FROM rp_alerts WHERE id = '$row[id]'") or die(mysql_error());
    ?>
    Any help is appreciated!
    Everyone hears what you say, friends listen to what you say, best friends listen to what you don't say.
    Radio DJ Panel v3 - It's Here!

  • #2
    Regular Coder
    Join Date
    Feb 2007
    Location
    near Washington, DC
    Posts
    135
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'd go about it something like this...

    Add a field to the DB 'expiretime.' This field initialized to NULL.

    Pseudocode Algorithm:
    Code:
    clear alertbuffer
    if expiretime is set {
        if current time > expiretime {
            delete row;
        } else {
            add message to alertbuffer;
        }
    } else {
        if ipaddr=toip {
            add message to alertbuffer;
            set expiretime=current time + 5 minutes;
        }
    }
    if alertbuffer { display alertbuffer }
    When the appropriate visitor comes to the site, the alert will be displayed (along with all other unexpired messages) and expiretime will be set to 5 minutes (or whatever) later.

    Once the expire time has been set, the message will be displayed (along with all other unexpired messages) to all users until the current time is later than the expire time. The first visitor after the message has expired will trigger the code that deletes the message.

    Now you just need to turn the pseudocode to actual code, which shouldn't be too difficult.

    Hope this helps.
    Last edited by phoenixshade; 03-11-2007 at 05:30 AM.
    — Wilford Nusser
    Validate Your Code: (X)HTML CSS
    An HTML Email is NOT a Web Page: HTML Email Guide (1.2Mb pdf) Webmail CSS Support
    REGEX: Brought to you by Psychotic Crack-Smoking Monkeys


  •  

    Posting Permissions

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