Forum Moderators: open

Message Too Old, No Replies

Need to extract specific date range data from db

         

JS_Harris

2:04 am on Nov 9, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I have an online text based roleplaying game that I'd like to add a "monthly winners" page to.

This is a sample of how the data is stored in the sql log file...

INSERT INTO `logs` VALUES (1, 2, 1, 1, 2, 'aaaaaaa', 1, 2000, 200, '08-11-2008 - 12:23:43', 1226172223);
INSERT INTO `logs` VALUES (2, 1, 2, 2, 1, 'admin', 1, -2000, 0, '08-11-2008 - 12:23:43', 1226172223);
INSERT INTO `logs` VALUES (3, 2, 1, 1, 2, 'aaaaaaa', 10, 19000, 1253, '08-11-2008 - 12:24:01', 1226172241);
INSERT INTO `logs` VALUES (4, 1, 2, 2, 1, 'admin', 10, -19000, 0, '08-11-2008 - 12:24:01', 1226172241);

As you can see the last two values are the timestamp of when the actions occured and the 6th value is the players name. The game doesn't reset, it continues on and allows players to build up profiles, so I have no specific monthly "totals" to draw from. How would I query this database to get the following...

- Final List of top 10 Players based on the highest "6th value" during the month of "month name".
- Running List of current top 10 players based on "6th value".

I would then need to create another table to store this information so that the "monthly winners" page doesn't need to query the entire rather sizable database continuously.

I've got this so far, it's highly unfinished.

$result = $db->query("SELECT * FROM logs WHERE GoStat=!");

The ! would be replaced with what to filter out a specific time period? (goStat is the timestamp table).
How would I get a running total limited to the past 30 days from this?

Hope thats not too confusing. It seems simple enough...

LifeinAsia

4:44 pm on Nov 10, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



- Final List of top 10 Players based on the highest "6th value" during the month of "month name".
- Running List of current top 10 players based on "6th value".

If the 6th value is the player's name, you're just sorting by the players' names. for your top 10 lists- doesn't make much sense.

As far as limiting the search, you'll need to use:
WHERE GoStat BETWEEN SomeStartDate AND SomeEndDate

physics

7:07 pm on Nov 11, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm confused :) The field names would help here, plus an explanation of the one you want to use to determine the monthly winners.
If, like you said, there is no total then you will probably need to first create a table that contains the total 'points' for each player for the past month (do this once per month), then delete all but the top 10 from that table, then you can query this small table every time you want to generate your top 10 list.