Okay I'm writing a script that goes like this:
echo "<table><tr><td><table cellspacing=0 class=border cellpadding=5><tr><th colspan=3>Offensive Matchup</th></tr>";
for($count=0;$count<$num_res;$count++){
$team1 = strtolower(mysql_result($res,"team") );
$wins = mysql_result($res,$count,"wins");
$loses = mysql_result($res,$count,"loses");
$ties = mysql_result($res,$count,"ties");
echo "<tr>";
echo "<th colspan=2 align=right><img src=/images/nfl_logos_large/" . strtolower($team1) . ".gif></th>";
}
$query = "select team, wins, loses, ties, pts_for, pts_agst from standings where league_id=$league_id and season=$season and team=\"$team2\" order by wins/(wins+loses) DESC LIMIT 1";
$res = mysql_query($query,$db);
$num_res = mysql_num_rows($res);
for($count=0;$count<$num_res;$count++){
$team2 = strtolower(mysql_result($res,"team") );
echo "<th><img src=/images/nfl_logos_large/" . strtolower($team2) . ".gif></th>";
echo "</tr>";
}
$query = "select team, wins, loses, ties, pts_for, pts_agst from standings where league_id=$league_id and season=$season and team=\"$team1\" order by wins/(wins+loses) DESC LIMIT 1";
$res = mysql_query($query,$db);
$num_res = mysql_num_rows($res);
for($count=0;$count<$num_res;$count++){
$team1 = strtolower(mysql_result($res,"team") );
$wins = mysql_result($res,$count,"wins");
$loses = mysql_result($res,$count,"loses");
$ties = mysql_result($res,$count,"ties");
if($week==1){
$wins = 0;
$loses = 0;
$ties = 0;
}
echo "<tr>";
echo "<td>Record</td>";
echo "<td>(" . $wins ."-" . $loses . "-" . $ties[$old_count + $count] . ")</td>";
}
$query = "select team, wins, loses, ties, pts_for, pts_agst from standings where league_id=$league_id and season=$season and team=\"$team2\" order by wins/(wins+loses) DESC LIMIT 1";
$res = mysql_query($query,$db);
$num_res = mysql_num_rows($res);
for($count=0;$count<$num_res;$count++){
$team2 = strtolower(mysql_result($res,"team") );
$wins = mysql_result($res,$count,"wins");
$loses = mysql_result($res,$count,"loses");
$ties = mysql_result($res,$count,"ties");
if($week==1){
$wins = 0;
$loses = 0;
$ties = 0;
}
echo "<td>(" . $wins ."-" . $loses . "-" . $ties[$old_count + $count] . ")</td>";
echo "</tr>";
}
echo "</table>";
?>
Okay, basically what I'm asking is how do I save myself a lot of time by not repeating the query and "for" sections over and over again (I plan on adding several more rows to this script). I know it's a lot of code, but if someone could lend me a hand I would be greatly obliged.
The script in action : http://www.pmlfootball.net/matchup.php?team1=Eagles&team2=Bears