Jump to content

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);

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.