doulai2573 2013-04-10 10:37
浏览 41
已采纳

致命错误:无法重新声明getteampoints()(之前在[关闭]中声明)

Got the following function and the getteampoints value wasn't declared anywhere before. Tried to follow other redececlare error problems but none of the worked. How can i fix this?

function getTeamPoints($team)
    {
        $query = mysql_query("SELECT * FROM Team_comp WHERE t_id='$team'");
        $team_array = array();

        while($a = mysql_fetch_array($query))
        {
            $team_array = array(            'home_won'  =>  $a['home_win'],
                                            'home_draw' =>  $a['home_tie'],
                                            'home_lost' =>  $a['home_lost'],
                                            'away_won'  =>  $a['away_win'],
                                            'away_draw' =>  $a['away_tie'],
                                            'away_lost' =>  $a['away_lost'],
                                            'home_games'=>  $a['home_games'],
                                            'away_games'=>  $a['away_games']);
        }

        return $team_array;
    }

    function calculateTeamPoints($team, $type)
    {
        $teamPts = getTeamPoints($team);

        if($type == 'home')
        {
            $homem = $teamPts['home_games'];
            $homew = $teamPts['home_won'];
            $percent = ($homew * 100) / $homem;

            $remaining = $homem - $homew;

            $per = ($remaining * 100) / $homem;
            $percent += $per / 2;
        }
        elseif($type == 'away')
        {
            $homem = $teamPts['away_games'];
            $homew = $teamPts['away_won'];
            $percent = ($homew * 100) / $homem;

            $remaining = $homem - $homew ;

            $per = ($remaining * 100) / $homem;
            $percent += $per / 2;
        }

        return $percent;
    }

    function getpercent($hometeamid, $awayteamid)
    {
        $hometeampts = calculateTeamPoints($hometeamid, 'home');
        $awayteampts = calculateTeamPoints($awayteamid, 'away');


        $homepercent = floor(($hometeampts - $awayteampts) + 50);
        $awaypercent = 100-$homepercent;


    }

    //demo
    getpercent($hometeamid, $awayteamid);
    ?>
  • 写回答

2条回答 默认 最新

  • dsfdsf23423 2013-04-10 10:40
    关注

    Putt the how function getTeamPoints inside IF condition..

    if(!function_exists('getTeamPoints')){ 
        function getTeamPoints()....
    
    }
    

    Its not possible too declare 1 function more than once!

    You have to write different name if you declare it more than 1 time, if you just include that file more than 1time (which is wrong..) this IF function exists check will work fine.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输