Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-11-2007, 04:46 AM   PM User | #1
Troy297
Regular Coder

 
Troy297's Avatar
 
Join Date: Oct 2006
Location: Earth
Posts: 314
Thanks: 10
Thanked 0 Times in 0 Posts
Troy297 is an unknown quantity at this point
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!
Troy297 is offline   Reply With Quote
Old 03-11-2007, 05:27 AM   PM User | #2
phoenixshade
Regular Coder

 
Join Date: Feb 2007
Location: near Washington, DC
Posts: 135
Thanks: 0
Thanked 0 Times in 0 Posts
phoenixshade is on a distinguished road
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.
__________________
— 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

Last edited by phoenixshade; 03-11-2007 at 05:30 AM..
phoenixshade is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:30 PM.


Advertisement
Log in to turn off these ads.