doujie9882 2016-05-06 02:15
浏览 41

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

I just tried out this code below and it doesn't seem to work. I corrected the bugs and it doesn't show nothing. It should show the standings array which I can then make it into a table. It's for Joomla MVC component that I'm working on. Can maybe somebody help me?

Thanks!

The code: EDIT:

    $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条回答 默认 最新

  • doucu7330 2016-05-06 02:44
    关注

    You are printing result of usort which is a boolean value. If you expect an array representation, then print the array itself:

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

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大