...

View Full Version : Plugin challange



gpimpin
10-24-2009, 05:36 AM
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 hacking 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 any help!

tomws
10-24-2009, 04:48 PM
Perhaps you need to tweak your query. Maybe adding something like ORDER BY `date` DESC would get them in the correct reversed (descending) order so that array[0] is the immediate previous by date.

I suspect they're pulling now in either ascending order or even unordered and you're seeing the first (oldest) result. That's further suggested by changing the array index to 1 and getting the second game.

EDIT: By the way, if that's the solution, you may also want to modify the query for next game. If the dates aren't inserted in an order that matches their natural order, you could get the same problem for that query. Just reverse the DESC to ASC in the previous snippet.

gpimpin
10-24-2009, 09:23 PM
Makes a lot of sense, I'll report back if it worked. Thanks!

gpimpin
10-24-2009, 09:30 PM
Okay I tried that (adding ORDER BY 'date' DESC) and the following error is thrown:

[You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY `date` ASC' at line 1]
SELECT `group`, `home_team`, `away_team`, DATE_FORMAT(`date`, '%Y-%m-%d %H:%i') AS date, DATE_FORMAT(`date`, '%e') AS day, DATE_FORMAT(`date`, '%c') AS month, DATE_FORMAT(`date`, '%Y') AS year, DATE_FORMAT(`date`, '%H') AS `hour`, DATE_FORMAT(`date`, '%i') AS `minutes`, `match_day`, `location`, `league_id`, `home_points`, `away_points`, `winner_id`, `loser_id`, `post_id`, `season`, `id`, `custom` FROM wp_leaguemanager_matches WHERE ( `home_team` = 1 OR `away_team` = 1 ) AND DATEDIFF(NOW(), `date`) > 0 ORDER BY `date` DESC ORDER BY `date` ASC

gpimpin
10-24-2009, 09:39 PM
okay I got some more advice and here is what looks to work...

$prev_match = end($prev_matches);

tomws
10-25-2009, 02:02 AM
That will work as long as the query is pulling results ordered by date, which it may be doing. Looking back at the error, there are two ORDER BY statements, so the original ORDER BY must have been in place already. Sorry for the confusion.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum