dongtang1966 2012-10-30 05:47
浏览 30

XML PHP表输出错误

Here is a part of my code where I extract XML data into a table using PHP. The problem is, the first row in my table is blank, (except for the checkboxes which never leave). Any help would be appreciated!

<!-- 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>';  
    ?>
  • 写回答

1条回答 默认 最新

  • dongyi2889 2012-10-30 06:09
    关注

    To actually understand the problem, we would need to see the content of your XML. However, a quick fix should be changing the for loop into this:

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

    PS: I'm not even sure what each foreach loop actually do.

    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?