Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
HOWTO: Room expire when no messages since 1 hour
Old 10-26-2006, 06:41 PM HOWTO: Room expire when no messages since 1 hour
Galaxian's Avatar
Rich Powell

Posts: 842
Name: Rich Powell
Location: United Kingdom
Trades: 0
I have a website that is a chat room network where you can join and create chat rooms.

I just need a basic php script on how deleting a room from the rooms table when there hasn't been any messages posted in it for .. lets say.. an hour.

the tables involved are:

Chat (table for the messages)
- posted (stores NOW() as datetime)
- room (the ID of the room its posted in)

Rooms
- id
- created

With that information could someone please help me conjure a script that cleans old rooms thanks
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Please help get the new
Please login or register to view this content. Registration is FREE
forum started for Webmasters like you!

Galaxian is offline
Reply With Quote
View Public Profile Visit Galaxian's homepage!
 
 
Register now for full access!
Old 10-28-2006, 03:08 PM Re: HOWTO: Room expire when no messages since 1 hour
Galaxian's Avatar
Rich Powell

Posts: 842
Name: Rich Powell
Location: United Kingdom
Trades: 0
bump::
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Please help get the new
Please login or register to view this content. Registration is FREE
forum started for Webmasters like you!

Galaxian is offline
Reply With Quote
View Public Profile Visit Galaxian's homepage!
 
Old 10-29-2006, 06:34 AM Re: HOWTO: Room expire when no messages since 1 hour
Ickie's Avatar
Extreme Talker

Posts: 217
Location: Australia
Trades: 0
PHP Code:
$timestamp time();
$timeout $timestamp-3600;

$query mysql_query("SELECT room FROM Chat WHERE posted<$timeout");
$row mysql_fetch_array($query);

if (!
$row) {
//do nothing 
} else {
mysql_query("DELETE FROM Rooms WHERE id='".$row["room"]."'");
mysql_query("DELETE FROM Chat WHERE room='".$row["room"]."'");

I think that should work...
Ickie is offline
Reply With Quote
View Public Profile
 
Old 10-29-2006, 08:59 AM Re: HOWTO: Room expire when no messages since 1 hour
Galaxian's Avatar
Rich Powell

Posts: 842
Name: Rich Powell
Location: United Kingdom
Trades: 0
Thank you very much for your response.

Though the code seems to have no effect and doesn't delete expired rooms.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Please help get the new
Please login or register to view this content. Registration is FREE
forum started for Webmasters like you!

Galaxian is offline
Reply With Quote
View Public Profile Visit Galaxian's homepage!
 
Old 10-29-2006, 01:08 PM Re: HOWTO: Room expire when no messages since 1 hour
Christopher's Avatar
Iced Cap

Latest Blog Post:
Cross-domain AJAX with JSONP
Posts: 3,110
Location: Toronto, Ontario
Trades: 0
There's no really efficient way, but you could use something liek this:

PHP Code:
$timesnip time() - 3600;
$q mysql_query("SELECT DISTINCT room, UNIX_TIMESTAMP(posted) AS posted FROM Chat ORDER BY posted DESC");

$ids = array();
while(
$msg mysql_fetch_assoc($q)) {
    
    if (
$msg['posted'] < $timesnip) {
        
$ids[] = $msg['room'];
    }
}

if (
$ids) {
    
$ids implode(','$ids);

    
mysql_query("DELETE FROM Chat WHERE room IN($ids)");
    
mysql_query("DELETE FROM Rooms WHERE id IN($ids)");

Untested, but may get you on the right track.
__________________

Please login or register to view this content. Registration is FREE
- Latest Articles:
Please login or register to view this content. Registration is FREE
,
Please login or register to view this content. Registration is FREE

--
Please login or register to view this content. Registration is FREE

Christopher is offline
Reply With Quote
View Public Profile
 
Old 10-29-2006, 09:42 PM Re: HOWTO: Room expire when no messages since 1 hour
Galaxian's Avatar
Rich Powell

Posts: 842
Name: Rich Powell
Location: United Kingdom
Trades: 0
Thank you very much, I think that one works a little better.

However, it seems to be naughty and just deleted the chat much too early.. wierd lol

Also is there a way to add in a way to stop it from deleting rooms, and their messages, which have their setting "permanent" set to "1"?
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Please help get the new
Please login or register to view this content. Registration is FREE
forum started for Webmasters like you!

Galaxian is offline
Reply With Quote
View Public Profile Visit Galaxian's homepage!
 
Old 10-30-2006, 04:30 PM Re: HOWTO: Room expire when no messages since 1 hour
Galaxian's Avatar
Rich Powell

Posts: 842
Name: Rich Powell
Location: United Kingdom
Trades: 0
I have commented out the code since it wasn't working efficiently.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Please help get the new
Please login or register to view this content. Registration is FREE
forum started for Webmasters like you!

Galaxian is offline
Reply With Quote
View Public Profile Visit Galaxian's homepage!
 
Old 11-01-2006, 08:57 PM Re: HOWTO: Room expire when no messages since 1 hour
Galaxian's Avatar
Rich Powell

Posts: 842
Name: Rich Powell
Location: United Kingdom
Trades: 0
bump::
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Please help get the new
Please login or register to view this content. Registration is FREE
forum started for Webmasters like you!

Galaxian is offline
Reply With Quote
View Public Profile Visit Galaxian's homepage!
 
Reply     « Reply to HOWTO: Room expire when no messages since 1 hour
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.29792 seconds with 12 queries