我的控制器中有这个代码:
$postlist->phaseList = $this->Project->LatestApplicablePlan->WBS->GetPhaseList($Options);
$PhaseList = $this->Project->LatestApplicablePlan->WBS->GetPhaseList($Options);
$postlist->Counter = COUNT($PhaseList);
for($x = 0; $x < COUNT($PhaseList); $x++)
{
foreach($PhaseList as $row) {
$TaskID = array( $row['TaskID'] );
$postlist->taskList = $this->Project->LatestApplicablePlan->WBS->GetWBS($TaskID[$x], $Options);
}
}
但我收到错误undefined offset : 1
。我在数据库中检索的数据不仅仅是单个数据。
答案 0 :(得分:2)
问题来自这一行:
$TaskID = array( $row['TaskID'] );
这相当于写作:
$TaskID = array(
0 => $row['TaskID']
);
尽管数组TaskID
中只有1个元素,但当$x
大于零时,会出现错误。
试试这个:
$PhaseList = $this->Project->LatestApplicablePlan->WBS->GetPhaseList($Options);
$postlist->phaseList = $PhaseList;
$postlist->Counter = COUNT($PhaseList);
foreach($PhaseList as $row) {
$postlist->taskList[] = $this->Project->LatestApplicablePlan->WBS->GetWBS($row['TaskID'], $Options);
}