得到了以下函數,並且getteampoints值沒有在之前的任何地方聲明過。試圖遵循其他redececlare錯誤問題,但沒有任何工作。我該如何解決這個問題?致命錯誤:無法重新聲明getteampoints()(先前在
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);
?>
你是否在任何地方包含這個函數文件?如果是,則嘗試使用'include_once'。 – Rikesh 2013-04-10 10:40:39
是你在這個腳本中包含任何php腳本。 – Bharanikumar 2013-04-10 11:12:59
當您嘗試定義已定義的函數時,通常會發生這種情況。如Rikesh所說,使用include_once。 – 2014-01-25 08:16:17