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.