gpimpin Posted October 24, 2009 Share Posted October 24, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/178811-solved-datediff-question/ Share on other sites More sharing options...
DavidAM Posted October 24, 2009 Share Posted October 24, 2009 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); Quote Link to comment https://forums.phpfreaks.com/topic/178811-solved-datediff-question/#findComment-943361 Share on other sites More sharing options...
gpimpin Posted October 24, 2009 Author Share Posted October 24, 2009 Thanks DavidAM I appreciate the help, I'll try that and report back. That makes sense! Quote Link to comment https://forums.phpfreaks.com/topic/178811-solved-datediff-question/#findComment-943363 Share on other sites More sharing options...
gpimpin Posted October 24, 2009 Author Share Posted October 24, 2009 Thanks so much, this worked like a charm... Quote Link to comment https://forums.phpfreaks.com/topic/178811-solved-datediff-question/#findComment-943629 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.