Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/248.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php mysql足球排名表脚本不工作_Php_Mysql_Joomla - Fatal编程技术网

php mysql足球排名表脚本不工作

php mysql足球排名表脚本不工作,php,mysql,joomla,Php,Mysql,Joomla,我只是尝试了下面的代码,它似乎不起作用。我纠正了错误,它没有显示任何内容。它应该显示排名数组,然后我可以将其放入一个表中。我正在为Joomla MVC组件工作。也许有人能帮帮我吗 谢谢 代码:编辑: $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select($db->quoteName(array('home' , 'scoreHome' , 'away' , 'sc

我只是尝试了下面的代码,它似乎不起作用。我纠正了错误,它没有显示任何内容。它应该显示排名数组,然后我可以将其放入一个表中。我正在为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 ;
    }

您正在打印的结果是一个布尔值。如果需要阵列表示,请打印阵列本身:


mysql标记之所以存在,是因为它访问数据库中的信息。@janip,但在您的帖子中没有访问数据库的代码是的,我没有复制它。在这里我编辑了它。虽然我非常喜欢在前端做这些事情,但在这个例子中,我想我应该在数据库中做。例如@janip,至少这是打印数组的方法。如果它是空的,那么可能没有向数组中添加任何内容。你读过了吗?是的,我正在弄明白为什么数组没有输入。
usort($standings, 'comparePoints');
print_r($standings);