Computer Webmaster Gaming Console Graphics Forum

Welcome to the Computer Webmaster Gaming Console Graphics Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

MK PitStop Main Earn $25 Earn Money Posting Extras Members Blogs Image Hosting User Pages
Go Back   Computer Webmaster Gaming Console Graphics Forum > Webmaster Forum > Website Coding > Database
Register FAQ/Rules Become A V.I.P. Member Search Today's Posts Mark Forums Read

Database Database problems or need to ask a question? maybe something to do with sql injections or a database software question. Database topics cover MySQL, PostgreSQL, Oracle, SQL Server or anything else related to databases.

Google
Reply
 
LinkBack Thread Tools Display Modes
Old 05-31-2007, 7:40 PM   #1
Andy in NJ
 
Andy in NJ's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default I need a "pruning" too for MySQL

I am looking for a tool that will allow me to "prune" my MySQL database by
entering a specific number of days since a particular entry was updated, and
if it exceeds that, it deletes the entry. Specifically, I have a database of
player statistics from an online game server and I want to make it so if
someone hasn't had their stats added to/updated, I want them deleted..


 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Reply With Quote
Advertisements
Old 05-31-2007, 7:40 PM   #2
Joseph Melnick
 
Joseph Melnick's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default I need a "pruning" too for MySQL

Andy in NJ Wrote:

"Andy in NJ" <ADMIN at FLOTSERVER DOT NET> wrote in message
news:R-udncBZysoNOiDfRVn-iA@comcast.com...
>I am looking for a tool that will allow me to "prune" my MySQL database by
>entering a specific number of days since a particular entry was updated,
>and if it exceeds that, it deletes the entry. Specifically, I have a
>database of player statistics from an online game server and I want to make
>it so if someone hasn't had their stats added to/updated, I want them
>deleted..


Hello Andy,

Does your table have a created OR modified field?

Given Table below:

create table stats (
id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
player_id INT NOT NULL,
stat INT NOT NULL DEFAULT '0',
modified DATETIME );


Running a query like the one shown below will identify data for player_id 's
that you want to prune.


SELECT a.player_id,MAX(a.modified)
FROM stats a
WHERE DATE_ADD( a.modified,INTERVAL 30 DAY) > now()
GROUP BY a.player_id;

NEXT:

DELETE FROM stats
WHERE player_id = IDENTIFIED TO BE DELETED

with PHP:

<?php
// deleteinactiveplayerdata.php
// delete inactive players stats older than this number of days old.
$lastmodified = "30";
$dbhost = "mydatabasehost";
$dbuser = "mydatabaseuser";
$dbpass = "mypassword";
$dbname = "mydatabase";
// connect to database
$dblink = mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db($dbname, $dblink);
// identify inactive players where most recent stat modified datetime
// plus $lastmodified days is less than now.
$query = "SELECT a.player_id, MAX(a.modified) max_modified " .
"FROM stats a " .
"WHERE DATE_ADD( a.modified,INTERVAL ".$lastmodified." DAY)
< now() " .
"GROUP BY a.player_id";
$result = mysql_query($query,$dblink);
while($row = mysql_fetch_array($result)) {
$player_id = $row["player_id"];
$max_modified = $row["max_modified"];
// delete all stats for players identified as inactive
$query2 = "DELETE FROM stats WHERE player_id = ".$player_id."";
mysql_query($query2,$dblink);
}

?>

I hope that this helps.

Joseph Melnick
JM Web Consultants
Toronto, Ontario, Canada
http://www.jphp.com/



 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Reply With Quote
Old 05-31-2007, 7:40 PM   #3
Andy in NJ
 
Andy in NJ's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default I need a "pruning" tool for MySQL


"Joseph Melnick" <jmelnick@jphp.com> wrote in message
news:epydnQPwmtYXXSDfRVn-jg@rogers.com...
> Does your table have a created OR modified field?

<snip>

I'm afraid this is beyond my expertise. I can log onto cpanel and go to
PHPMyAdmin and run commands. I would load a certian table, which contains an
entry for each player's name. In that table is a date, in Linux format, that
says when it was last updated.


 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Reply With Quote
Old 05-31-2007, 7:40 PM   #4
Joseph Melnick
 
Joseph Melnick's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default I need a "pruning" tool for MySQL

Andy in NJ Wrote:

"Andy in NJ" <ADMIN at FLOTSERVER DOT NET> wrote in message
news:t8ednV3Qs-NASCDfRVn-2A@comcast.com...
>
> "Joseph Melnick" <jmelnick@jphp.com> wrote in message
> news:epydnQPwmtYXXSDfRVn-jg@rogers.com...
>> Does your table have a created OR modified field?

> <snip>
>
> I'm afraid this is beyond my expertise. I can log onto cpanel and go to
> PHPMyAdmin and run commands. I would load a certian table, which contains
> an entry for each player's name. In that table is a date, in Linux format,
> that says when it was last updated.


Run the first Query in PHPMyAdmin to get the list of Players that match your
criteria and change INTERVAL 30 DAY to the number of inactive days that
makes sense. This will give you a list of player_id's, and when they were
last modified.


SELECT a.player_id,MAX(a.modified)
FROM players a
WHERE DATE_ADD( FROM_UNIXTIME(a.modified),INTERVAL 30 DAY) < now()
GROUP BY a.player_id;

Get:
player_id modified
1 2005-01-01 12:00:00
5 2005-04-28 01:39:22
....
212 2004-12-31 23:59:59


then run this Query where player is in a comma separated list of
player_id's:

DELETE FROM stats WHERE player_id IN (1, 5, ....,212);


Joseph Melnick
JM Web Consultants
Toronto, Ontario, Canada
http://www.jphp.com/



 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Reply With Quote
Old 05-31-2007, 7:41 PM   #5
Matthias Hoys
 
Matthias Hoys's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default I need a "pruning" tool for MySQL


"Joseph Melnick" <jmelnick@jphp.com> wrote in message
news:Ad2dnROpdevBVCPfRVn-hw@rogers.com...
> Andy in NJ Wrote:
>
> "Andy in NJ" <ADMIN at FLOTSERVER DOT NET> wrote in message
> news:t8ednV3Qs-NASCDfRVn-2A@comcast.com...
>>
>> "Joseph Melnick" <jmelnick@jphp.com> wrote in message
>> news:epydnQPwmtYXXSDfRVn-jg@rogers.com...
>>> Does your table have a created OR modified field?

>> <snip>
>>
>> I'm afraid this is beyond my expertise. I can log onto cpanel and go to
>> PHPMyAdmin and run commands. I would load a certian table, which contains
>> an entry for each player's name. In that table is a date, in Linux
>> format, that says when it was last updated.

>
> Run the first Query in PHPMyAdmin to get the list of Players that match
> your criteria and change INTERVAL 30 DAY to the number of inactive days
> that makes sense. This will give you a list of player_id's, and when they
> were last modified.
>
>
> SELECT a.player_id,MAX(a.modified)
> FROM players a
> WHERE DATE_ADD( FROM_UNIXTIME(a.modified),INTERVAL 30 DAY) < now()
> GROUP BY a.player_id;
>
> Get:
> player_id modified
> 1 2005-01-01 12:00:00
> 5 2005-04-28 01:39:22
> ...
> 212 2004-12-31 23:59:59
>
>
> then run this Query where player is in a comma separated list of
> player_id's:
>
> DELETE FROM stats WHERE player_id IN (1, 5, ....,212);
>
>
> Joseph Melnick
> JM Web Consultants
> Toronto, Ontario, Canada
> http://www.jphp.com/
>
>
>


Why not :

DELETE FROM stats WHERE player_id IN (
SELECT a.player_id,MAX(a.modified)
FROM players a
WHERE DATE_ADD( FROM_UNIXTIME(a.modified),INTERVAL 30 DAY) < now()
GROUP BY a.player_id;
);


Matthias


 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Reply With Quote
Old 05-31-2007, 7:41 PM   #6
Joseph Melnick
 
Joseph Melnick's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default I need a "pruning" tool for MySQL

Mr. Hoys Wrote:

"Matthias Hoys" <idmwarpzone_NOSPAM_@yahoo.com> wrote in message
news:42bf0c94$0$325$ba620e4c@news.skynet.be...
>
> "Joseph Melnick" <jmelnick@jphp.com> wrote in message
> news:Ad2dnROpdevBVCPfRVn-hw@rogers.com...
>> Andy in NJ Wrote:
>>
>> "Andy in NJ" <ADMIN at FLOTSERVER DOT NET> wrote in message
>> news:t8ednV3Qs-NASCDfRVn-2A@comcast.com...
>>>
>>> "Joseph Melnick" <jmelnick@jphp.com> wrote in message
>>> news:epydnQPwmtYXXSDfRVn-jg@rogers.com...
>>>> Does your table have a created OR modified field?
>>> <snip>
>>>
>>> I'm afraid this is beyond my expertise. I can log onto cpanel and go to
>>> PHPMyAdmin and run commands. I would load a certian table, which
>>> contains an entry for each player's name. In that table is a date, in
>>> Linux format, that says when it was last updated.

>>
>> Run the first Query in PHPMyAdmin to get the list of Players that match
>> your criteria and change INTERVAL 30 DAY to the number of inactive days
>> that makes sense. This will give you a list of player_id's, and when they
>> were last modified.
>>
>>
>> SELECT a.player_id,MAX(a.modified)
>> FROM players a
>> WHERE DATE_ADD( FROM_UNIXTIME(a.modified),INTERVAL 30 DAY) < now()
>> GROUP BY a.player_id;
>>
>> Get:
>> player_id modified
>> 1 2005-01-01 12:00:00
>> 5 2005-04-28 01:39:22
>> ...
>> 212 2004-12-31 23:59:59
>>
>>
>> then run this Query where player is in a comma separated list of
>> player_id's:
>>
>> DELETE FROM stats WHERE player_id IN (1, 5, ....,212);
>>
>>
>> Joseph Melnick
>> JM Web Consultants
>> Toronto, Ontario, Canada
>> http://www.jphp.com/
>>
>>
>>

>
> Why not :
>
> DELETE FROM stats WHERE player_id IN (
> SELECT a.player_id,MAX(a.modified)
> FROM players a
> WHERE DATE_ADD( FROM_UNIXTIME(a.modified),INTERVAL 30 DAY) < now()
> GROUP BY a.player_id;
> );
>
>
> Matthias


Hello Mattias,

Depending on the version of MySQL that Andy is using he may not be able to
do a sub select as you suggest.

Joseph Melnick
JM Web Consultants
Toronto, Ontario, Canada
http://www.jphp.com/






 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Reply With Quote
Featured Websites
Free Space
Free Space
Free Space Free Space
Reply
Tags: ,




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Database "pruning" tool? Andy in NJ Database 5 05-31-2007 7:41 PM
mysql 4.0.x - ORDER BY ? GROUP BY ? please help me for "hierarchical"query MultiTaskinG Database 0 05-31-2007 7:40 PM
For Sony, that performance "is simply abysmal" - "PS3 is sucking wind right now" elrous0@pop.uky.edu Console Subjects 7 05-29-2007 3:25 PM
some shortcut keys not working anymore-----help"""""""" Kadaitcha Man Windows 1 05-28-2007 10:28 PM


Featured Websites




All times are GMT +1. The time now is 7:29 PM.


Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.0.0
Cheap Computers
MK PitStop Copyright 2005 - 2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98