2012-10-30 103 views
0

這裏是我的代碼的一部分,我使用PHP將XML數據提取到表中。問題是,我表中的第一行是空白的(除了從不離開的複選框)。任何幫助,將不勝感激!XML PHP表輸出錯誤

<!-- language-all: lang-php --> 
<?php 
    $AwayMoneyLine[] = (string)$xml2->moneyline_visiting; 
    $HomeMoneyLine[] = (string)$xml2->moneyline_home; 
    $AwaySpreadAdjust[] = (string)$xml2->spread_adjust_visiting; 
    $HomeSpreadAdjust[] = (string)$xml2->spread_adjust_home; 
    $AwayLine[] = (string)$xml2->spread_visiting; 
    $HomeLine[] = (string)$xml2->home_visiting; 
    $UnderAdjust[] = (string)$xml2->under_adjust; 
    $OverAdjust[] = (string)$xml2->over_adjust; 
    $ATotalPoints[] = (string)$xml2->total_points; 
    $Date[] = (string)$xml->Date; 
    $AwayTeam[] = (string)$xml->AwayTeam; 
    $HomeTeam[] = (string)$xml->HomeTeam; 
    $AwayRotation[] = (string)$xml->AwayRotation; 
    $HomeRotation[] = (string)$xml->HomeRotation; 
    $Total = (string)$xml->Total; 
    $OverPrice[] = (string)$xml->OverPrice; 
    $UnderPrice[] = (string)$xml->UnderPrice; 
    $Line[] = (string)$xml->Line; 
    $AwayTeamPrice[] = (string)$xml->AwayTeamPrice; 
    $HomeTeamPrice[] = (string)$xml->HomeTeamPrice; 
    $AwayTeamMoneyLine = (string)$xml->AwayTeamMoneyLine; 
    $HomeTeamMoneyLine = (string)$xml->HomeTeamMoneyLine; 
    $Title = (string)$xml->Title; 
    echo '<table cellpadding="0" cellspacing="0" border="1" bordercolor="#585858" width=100%>';  
    echo '<tr>'; 
    echo '<th>Date</th>'; 
    echo '<th>#</th>'; 
    echo '<th>Team</th>'; 
    echo '<th>Money</th>'; 
    echo '<th>Spread</th>'; 
    echo '<th>Total</th>'; 
    echo '</tr>'; 
    $count = count($Game);  
    for($i=0; $i<20;){ 
    $AwayTeamSpread = " ";  
    $HomeTeamSpread = " "; 
    foreach ($xml->Game as $Game) { 
    $Date[] = $Game->Date; $AwayTeam[] = $Game->AwayTeam; $HomeTeam[] = $Game->HomeTeam; $AwayRotation[] = $Game->AwayRotation; 
    $HomeRotation[] = $Game->HomeRotation; $Total[] = $Game->Total; $OverPrice[] = $Game->OverPrice; 
    $UnderPrice[] = $Game->UnderPrice; $Line[] = $Game->Line; $AwayTeamPrice[] = $Game->AwayTeamPrice; 
    $HomeTeamPrice[] = $Game->HomeTeamPrice; $AwayTeamMoneyLine[] = $Game->AwayTeamMoneyLine; $HomeTeamMoneyLine[] = $Game->HomeTeamMoneyLine; 
    } 
    foreach ($xml2->events->event as $event) { 
    $Spread = $event->periods->period[0]->spread; 
    $TotalPoints = $event->periods->period[0]->total;  
    $AwayLine[] = $Spread->spread_visiting; 
    $HomeLine[] = $Spread->spread_home; 
    $UnderAdjust[] = $TotalPoints->under_adjust; 
    $OverAdjust[] = $TotalPoints->over_adjust; 
    $ATotalPoints[] = $TotalPoints->total_points; 
    $AwayMoneyLine[] = $MoneyLine->moneyline_visiting; 
    $HomeMoneyLine[] = $MoneyLine->moneyline_home; 
    $AwaySpreadAdjust[] = $Spread->spread_adjust_visiting; 
    $HomeSpreadAdjust[] = $Spread->spread_adjust_home; 
    }  
    echo '<tr>'; 
    echo "<td>$Date[$i]</td><td><table><tr><td>$AwayRotation[$i]</td></tr><tr><td>$HomeRotation[$i]</td></tr></table></td><td><table><tr><td>$AwayTeam[$i]</td></tr><tr><td>$HomeTeam[$i]</td></tr></table></td><td><table><tr><td><input type='checkbox'/> $AwayTeamMoneyLine[$i]</td></tr><tr><td><input type='checkbox'/>$HomeTeamMoneyLine[$i]</td></tr></table></td><td><table><tr><td><input type='checkbox'/> $AwayLine[$i] ($AwaySpreadAdjust[$i])</td></tr><tr><td><input type='checkbox'/> $HomeLine[$i] ($HomeSpreadAdjust[$i])</td></tr></table></td><td><table><tr><td><input type='checkbox'/> Over $ATotalPoints[$i]</td></tr><tr><td><input type='checkbox'/> Under $ATotalPoints[$i]</td></tr></table></td>"; 
    echo '</tr>'; 
    $i++; 
} 
    echo '<tr>'; 
    echo '<td colspan="3"><input type="submit" name="send" value="Submit"></td><td colspan="3"><input type="button" name="Clear" value="Clear" /></td>'; 
    echo '</tr>'; 
    echo ' </table>'; 
    ?> 
+0

對不起,但是錯誤是什麼? – tradyblix

+0

當我打印到表格中時,表格的第一行對於所有值都是空的。第二行是第一組數據,即。 $ i = 0 –

回答

1

要真正理解問題,我們需要查看XML的內容。然而,速戰速決應萬變的for循環到這一點:

for ($i = 1; $i <= 20) 

PS: 我甚至不知道什麼每個foreach循環實際上做。

+0

感謝您的臨時解決方案。如果我明天提供屏幕截圖並提供更多詳細信息,您是否可以提供更多見解? –

+0

我很樂意提供幫助。雖然我會很感激,如果你能給我更多關於這些foreach循環應該做什麼的細節。我想如果它不是for循環,那麼foreach循環可能與你的問題有關。 –