I run a fantasy football league.
I would like to create a page on our website that will allow people to see how each team’s wins-losses vs. all other active teams in the league.
Example where Team A has been selected:
Team A’s Record vs. Team B
Wins 2 Losses 1 Draws 0
Last game played 145.2 -132.6
TeamA’s Record vs. Team C
Wins 0 Losses 5 Draws 0
Last game played 122.3-155.6
TeamA’s Record vs. Team D
Wins 1 Losses 0 Draws 0
Last game played 143.2-115.2
so on and so on.
I have written a query and it works perfectly.
My problem is the PHP while loop. I cannot get the correct format down so that it works correctly.
Here is the query and php code:
[php]
$query = "select selected.teamname AS selected_team, selected_score.score AS selected_score, week.week, year, home_id, ".
"target_score.score as target_score, target.teamname as targetname, week.ID ".
"from owners as selected ".
"JOIN game_scores AS selected_score ON selected.owner_id = selected_score.team_id ".
"JOIN game_setup ON game_setup.game_id = selected_score.game_id ".
"JOIN game_scores AS target_score ON target_score.game_id = game_setup.game_id AND target_score.team_id != selected_score.team_id ".
"JOIN owners AS target ON target.owner_id = target_score.team_id ".
"JOIN week ON week.week = game_setup.week ".
"WHERE selected.owner_id = $thing ".
"and target.active = 1 ".
"GROUP BY target.teamname, year, week.ID ";
$result = mysql_query($query);
if (!$result) {
die('Invalid query: ’ . mysql_error());
}
$wins=0;
$losses=0;
$draws=0;
$a = ‘true’;
$b = ‘true’;
while($row = mysql_fetch_array($result))
{
if ($a = $b){
$last_target[‘targetname’] = $row[‘targetname’];
$a = ‘false’;
}
if ($last_target[‘targetname’] != $row[‘targetname’])
{
$last_target = $row;
printf(’
<table class="style1" border="1" width="400">
<tr>
<th>Opponent Name:</th>
<th colspan="2">%s</th>
</tr>
<tr>
<th>Wins</th>
<th>Losses</th>
<th>Draws</th>
</tr>
<tr>
<td align="center">%d</td>
<td align="center">%d</td>
<td align="center">%d</td>
</tr>
<tr>
<th>Last Game:</th>
<td colspan="2">%s of %s: %.1f - %.1f</td>
<tr>
</table><br/>',
$last_target['targetname'],
$wins,
$losses,
$draws,
$last_target['week'],
$last_target['year'],
$last_target['selected_score'],
$last_target['target_score']
);
$wins = $losses = $draws = 0;
}
if ($row[‘selected_score’] < $row[‘target_score’])
++$losses;
elseif ($row[‘selected_score’] == $row[‘target_score’])
++$draws;
else
++$wins;
$last_target = $row;
}
[/php]
I either get where the results start one row in and I get a blank box for the first result and it leaves off a team or where $last_target is always = to $row so nothing is printed to the screen.
Any help would be appreciated
Thank you for your time and effort.