Да без проблем могу скрипт:
include ('db.php');
function sortByPoints($a,$b)
{
if($a['points']==$b['points'])
{
$ppg_a='SELECT home_score,away_score FROM table WHERE tourn="'.$tourn.'" AND tourn_g="'.$group.'" AND sport ="'.$sport.'" AND year ="'.$year.'" AND home="'.$a.'" AND away="'.$b.'"';
$res_a=mysql_query($ppg_a);
$g_a = mysql_fetch_array($res_a);
$ppg_b='SELECT home_score,away_score FROM table WHERE tourn="'.$tourn.'" AND tourn_g="'.$group.'" AND sport ="'.$sport.'" AND year ="'.$year.'" AND home="'.$b.'" AND away="'.$a.'"';
$res_b=mysql_query($ppg_b);
$g_b = mysql_fetch_array($res_b);
$razn_a=$g_a['home_score']+$g_b['away_score'];
$razn_b=$g_b['home_score']+$g_a['away_score'];
if($razn_a==$razn_b)
{
if($a['difference']==$b['difference'])
{
if($a['goals_f']==$b['goals_f']) {return 0;}
elseif($a['goals_f']>$b['goals_f']) {return -1;}
else {return 1;}
}
elseif($a['difference']>$b['difference']) {return -1;}
else {return 1;}
}
if($razn_a>$razn_b) {return -1;}
else {return 1;}
if($a['wins']>$b['wins']) {return -1;}
else {return 1;}
}
elseif($a['points']>$b['points']) {return -1;}
else {return 1;}
}
$points='SELECT home, away, home_score, away_score,home_town,away_town FROM table WHERE tourn="'.$tourn.'" AND tourn_g="'.$group.'" AND sport ="'.$sport.'" AND year ="'.$year.'"';
$result=mysql_query($points);
if($result)
{
$a=array();
while ($row = mysql_fetch_array($result,MYSQL_ASSOC))
{
$team1=$row['home'];
$team2=$row['away'];
if(!isset($a[$team1]))
{
$a[$team1]=array('wins'=>0,'loses'=>0,'goals_a'=>0,'goals_f'=>0,'draws'=>0,'games'=>0,'points'=>0,'difference'=>0,'penalty'=>0);
}
if(!isset($a[$team2]))
{
$a[$team2]=array('wins'=>0,'loses'=>0,'goals_a'=>0,'goals_f'=>0,'draws'=>0,'games'=>0,'points'=>0,'difference'=>0,'penalty'=>0);
}
if ($row['home_score']!=null AND $row['away_score']!=null)
{
$a[$team1]['games']++;
$a[$team2]['games']++;
}
else
{
$a[$team1]['games'];
$a[$team2]['games'];
}
if($row['home_score']>$row['away_score'])
{
$a[$team1]['wins']++;
$a[$team2]['loses']++;
}
elseif($row['home_score']<$row['away_score'])
{
$a[$team1]['loses']++;
$a[$team2]['wins']++;
}
else
{if ($row['home_score']!=null AND $row['away_score']!=null)
{
$a[$team1]['draws']++;
$a[$team2]['draws']++;
} else {
$a[$team1]['draws'];
$a[$team2]['draws'];
}
}
if (empty($penalty[$team1]['penalty_points'])) {end;} else {$a[$team1]['penalty']=+$penalty[$team1]['penalty_points'];}
if (empty($penalty[$team2]['penalty_points'])) {end;} else {$a[$team2]['penalty']=+$penalty[$team2]['penalty_points'];}
$a[$team1]['points']=+$a[$team1]['wins']*3+$a[$team1]['draws']*1-$a[$team1]['penalty'];
$a[$team2]['points']=+$a[$team2]['wins']*3+$a[$team2]['draws']*1-$a[$team2]['penalty'];
$a[$team1]['goals_a']+=$row['home_score'];
$a[$team2]['goals_a']+=$row['away_score'];
$a[$team2]['goals_f']+=$row['home_score'];
$a[$team1]['goals_f']+=$row['away_score'];
$a[$team1]['difference']=$a[$team1]['goals_a']-$a[$team1]['goals_f'];
$a[$team2]['difference']=$a[$team2]['goals_a']-$a[$team2]['goals_f'];
$a[$team1]['town']=$row['home_town'];
$a[$team2]['town']=$row['away_town'];
}
uasort($a,'sortByPoints');
$tours=count($a);
$q20=array();
$tours_c=1;
echo "<table border=1 cellspacing=0 class=table>";
echo "<tr bgcolor=#CCCCCC>";
echo "<th class=table>№</th><th class=table>Команда</th>";
while ($tours_c!=$tours+1) {echo "<th class=table>$tours_c</th>";
$tours_c++;}
echo "<th class=table>Игры</th><th class=table>В</th><th class=table>Н</th><th class=table>П</th><th class=table>Голы</th><th class=table>Очки</th></tr>";
$l=1;
foreach($a as $q20team=>$qq20)
{
if (Нужный город==$qq20['town']) {$font="#FFFFCC";} else {$font="#FFFFFF";}
$q30=array();
echo "<tr bgcolor=$font><td align=center width=20 class=table>$l</td>";
echo "<td width=260 class=table align=left>\"$q20team\" ({$qq20['town']})</td>";
foreach($a as $ddteam=>$qq)
{
if ($q20team!=$ddteam) {
$query40 = '(SELECT id,home,away,home_score,away_score FROM table WHERE home="'.$q20team.'" AND away="'.$ddteam.'" AND tourn="'.$tourn.'" AND tourn_g="'.$group.'" AND sport ="'.$sport.'" AND year ="'.$year.'")
UNION ALL
(SELECT id,home,away,home_score,away_score FROM table WHERE home="'.$ddteam.'" AND away="'.$q20team.'" AND tourn="'.$tourn.'" AND tourn_g="'.$group.'" AND sport ="'.$sport.'" AND year ="'.$year.'")
ORDER BY id';
$result40 = mysql_query($query40) or die(mysql_error());
echo '<td align="center" width="40" class=table>';
while($p40 = mysql_fetch_array($result40)) {
if ($p40['home']==$q20team AND $p40['home_score']>$p40['away_score']) {$mcol1="#FF0000";} else {if ($p40['home']==$q20team AND $p40['home_score']<$p40['away_score']) {$mcol1="#000000";} else {$mcol1="#0066FF";}}
if ($p40['away']==$q20team AND $p40['away_score']>$p40['home_score']) {$mcol2="#FF0000";} else {if ($p40['away']==$q20team AND $p40['away_score']<$p40['home_score']) {$mcol2="#000000";} else {$mcol2="#0066FF";}}
if (!isset($p40['home_score']) AND !isset($p40['away_score'])) {echo " <br>";} else {
if ($p40['home']==$q20team) { echo '<font color='.$mcol1.'>'.$p40['home_score'].':'.$p40['away_score'].'</font><br>';}
else {echo '<font color='.$mcol2.'>'.$p40['away_score'].':'.$p40['home_score'].'</font><br>';}}
}
echo "</td>";} else {echo '<td align="center" width="30" class=table bgcolor=#000000>';}
}
echo "<td align=center width=40 class=table>{$qq20['games']}</td>";
echo "<td align=center width=30 class=table>{$qq20['wins']}</td>";
echo "<td align=center width=30 class=table>{$qq20['draws']}</td>";
echo "<td align=center width=30 class=table>{$qq20['loses']}</td>";
echo "<td align=center width=60 class=table>{$qq20['goals_a']}-{$qq20['goals_f']}</td>";
echo "<td align=center width=45 class=table><strong>{$qq20['points']}</strong></td>";
echo "</tr>";
$l++;
}
echo "</table><br>";
}
else
{
die(mysql_error());
}