PDA

View Full Version : Counting Timestamps?


Jaxel
02-10-2009, 08:44 PM
I'm working on that ranking script that I've been asking for the past couple of months...

One of the things I want to do, when I am calculating the rankings... I want to outdate older events... Events are all given a unix timestamp...

I am using the following code to calculate rankings... and so far its working great...

SELECT * FROM rank_scores
INNER JOIN rank_events ON(rank_scores.eventID = rank_events.eventID)
WHERE rank_scores.playerID = ".$player['playerID']."
ORDER BY sValue DESC, eDate DESC

As you can see, it takes all the earned scores that match a player's ID, from the rank_scores table (joined to the rank_event table), and sorts them by the highest earned scores and down (and additionally sorts by the event date). What I want to do is add in an extra WHERE statement... something along the lines of...

(currentTime - eDate) < $countDmod months

I defined the $countDmod variable as 12 in my config file. So what this should do, it will take the current date, subtract the date of the event from it... and if the remaining value is less than 12 months; it will add it to the SELECT statement, otherwise skip it.

How do I program this?

Dismounted
02-11-2009, 05:25 AM
$cutoff = strtotime('-12 Months');
SELECT *
FROM rank_scores
INNER JOIN rank_events USING (eventID)
WHERE rank_scores.playerID = $player[playerID]
AND eDate > $cutoff
ORDER BY sValue DESC, eDate DESC

Jaxel
02-11-2009, 10:10 AM
Thanks man! Thats exactly what I am looking for... but now I am having another issue...

I have 3 files...

/includes/config.php
/includes/function_player.php
/player.php

2 variables are declared and set in config.php: $countEmod and $countDmod...

config.php and function_player.php are called in /player.php with
require_once('./includes/config.php');
require_once('./includes/functions_player.php');

Then inside /player.php, I am calling up a function in functions_player.php
fetch_player($player);

So far, everything works great... however, inside the fetch_player function, I try to use those two global variables... $countEmod and $countDmod... Unfortunately, this doesn't work. The function doesn't recieve values for these variables. I have tried adding a require_once for the config file inside the functions file, but that too doesn't work.

Is there something I have to do, to get the global variables to work inside the function?

Dismounted
02-11-2009, 10:31 AM
You must use the global keyword to bring the variables into scope.
global $var1, $var2;

Jaxel
02-11-2009, 10:53 AM
Ah... kick ass...

I'm a PERL programmer by heart... PHP is just foreign to me.