Jump to content

[SOLVED] DATEDIFF Question


gpimpin

Recommended Posts

First time post, and of course it is a help question.

 

I am using a WP plug-in to display previous and next games in a season. (Leaguemanager is the plug-in name - Link http://wordpress.org/extend/plugins/leaguemanager/ ). The challenge I am having is that the previous game only displays the first game of the season, not the actual previous game...

 

The following code is pulled from the shortcode.php file in the lib folder of the plugin.

Here is the code for the next game which works...

 

$next_matches = $leaguemanager->getMatches("( `home_team` = {$team->id} OR

`away_team` = {$team->id} ) AND DATEDIFF(NOW(), `date`) <= 0");

$next_match = $next_matches[0];

 

Here is the code for the previous game that pulls the first game of the

season, not the actual previous game.

 

$prev_matches = $leaguemanager->getMatches("( `home_team` = {$team->id} OR

`away_team` = {$team->id} ) AND DATEDIFF(NOW(), `date`) > 0");

$prev_match = $prev_matches[0];

 

It's probably something really simple, but I have been ahcking away at this for about 8 hours and I cannot get it to work. On a side note if you swap the "0" for a "1" in this line $prev_match = $prev_matches[0]; it will show the second game of the season.

 

Thanks for ant help!

Link to comment
https://forums.phpfreaks.com/topic/178811-solved-datediff-question/
Share on other sites

Without seeing the code for the getMatches method, I have to guess that it is returning an array of matches.  The parameter looks like an SQL WHERE clause.  If the method does in fact return all of the matches that satisfy the WHERE clause, then you probably need to get the last entry in the array:

$prev_matches = $leaguemanager->getMatches("( `home_team` = {$team->id} OR
`away_team` = {$team->id} ) AND DATEDIFF(NOW(), `date`) > 0");
$prev_match = $prev_matches[count($prev_matches)-1];
// or maybe 'end' would be better
$prev_match = end($prev_matches);

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.