php mysql足球排名表脚本不起作用

时间:2016-05-06 02:15:58

标签: php mysql joomla

我刚刚尝试了下面的代码,它似乎不起作用。我纠正了错误,它没有显示任何内容。它应该显示标题数组,然后我可以将它组成一个表。这是我正在研究的Joomla MVC组件。也许有人可以帮助我吗?

谢谢!

代码:编辑:

    $db = JFactory::getDbo();

    $query = $db->getQuery(true);

    $query->select($db->quoteName(array('home' , 'scoreHome' , 'away' , 'scoreAway')));
   $query->from($db->quoteName('futliga_pc_liga1'));

    $db->setQuery($query);
    $rows = $db->loadAssocList();

$standings = array ();
$standingTemplate = array ('matches' => 0, 'wins' => 0, 'draws' => 0,    'losses' => 0, 'scoreHome' => 0, 'scoreAway' => 0, 'goalsdiff' => 0, 'points' => 0);

foreach ($rows as $row) {

    handleMatch($row['home'], $row['scoreHome'], $row['scoreAway']);
    handleMatch($row['away'], $row['scoreAway'], $row['scoreHome']);

    echo '<pre>';
    print_r( usort($standings, 'comparePoints' ) );  
}

function handleMatch($team, $scoreHome, $scoreAway){
    global $standings, $standingTemplate;
    if ($scoreHome > $scoreAway) 
    {
    $points = 3;
    $win = 1;
    $draw = 0;
    $loss = 0;
}
elseif ($scoreHome == $scoreAway) 
{
    $points = 1;
    $win = 0;
    $draw = 1;
    $loss = 0;
}
else 
{
    $points = 0;
    $win = 0;
    $draw = 0;
    $loss = 1;
}

if ( empty($standings[$team])){
    $standing = $standingTemplate;
} else {
    $standing = $standings[$team];


$standingTemplate['matches']++;
$standingTemplate['wins'] += $win;
$standingTemplate['draws'] += $draw;
$standingTemplate['losses'] += $loss;
$standingTemplate['scoreHome'] += $scoreHome;
$standingTemplate['scoreAway'] += $scoreAway;
$standingTemplate['goalsdiff'] += $scoreHome - $scoreAway;
$standingTemplate['points'] += $points;
}

$standings[$team] = $standing;

 }

function comparePoints($a, $b){
    if ($a['points'] == $b['points']) {
    if ($a['goalsdiff'] == $b['goalsdiff']) return 0;
    return ($a['goalsdiff'] < $b['goalsdiff']) ? 1 : -1 ;
    }       
    return ($a['points'] < $b['points']) ? 1 : -1 ;
    }

1 个答案:

答案 0 :(得分:0)

您正在打印usort的结果,这是一个布尔值。如果您期望数组表示,则打印数组本身:

usort($standings, 'comparePoints');
print_r($standings);