【发布时间】:2013-04-10 10:37:50
【问题描述】:
获得了以下函数,并且之前没有声明 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。 -
你是否在这个脚本中包含任何 php 脚本。
-
这通常发生在您尝试定义已定义的函数时。正如 Rikesh 所说,使用 include_once。