0

これは、PHP を使用して XML データをテーブルに抽出するコードの一部です。問題は、テーブルの最初の行が空白であることです (決して出ないチェックボックスを除く)。どんな助けでも大歓迎です!

<!-- 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>';  
    ?>
4

1 に答える 1

1

問題を実際に理解するには、XML の内容を確認する必要があります。ただし、簡単な修正として、for ループを次のように変更する必要があります。

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

PS: 各 foreach ループが実際に何をするのかさえわかりません。

于 2012-10-30T06:09:45.323 に答える