2012-10-26 44 views
0

我似乎無法回顯我的數組內容。出於某種原因,只有來自我所有陣列的第二個值正在顯示。任何幫助將不勝感激。 php代碼如下:在數組上循環迭代的問題

<?php 
// Characters from each item 
$char = 200; 
echo '<table cellpadding="0" align="left" cellspacing="0" border="1" bordercolor="#585858" width=100%>'; 
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; 
    // # items to display 
    $count    = 20; 
    for ($i = 0; $i < $count; $i++) { 
     $AwayTeamSpread   = " "; 
     $HomeTeamSpread   = " "; 
     $arrayDate    = $Date; 
     $arrayARotation   = $AwayRotation; 
     $arrayHRotation   = $HomeRotation; 
     $arrayAwayTeam   = $AwayTeam; 
     $arrayHomeTeam   = $HomeTeam; 
     $arrayTotal    = $Total; 
     $arrayLine    = $Line; 
     $arrayOverPrice   = $OverPrice; 
     $arrayUnderPrice  = $UnderPrice; 
     $arrayAwayTeamMoneyLine = $AwayTeamMoneyLine; 
     $arrayHomeTeamMoneyLine = $HomeTeamMoneyLine; 
     $arrayAwayTeamPrice  = $AwayTeamPrice; 
     $arrayHomeTeamPrice  = $HomeTeamPrice; 
     $arrayLine    = $Line; 
     $LineStrip    = str_replace("-", " ", $arrayLine); 

     if ($arrayHomeTeamMoneyLine > 0); { 
      $AwayTeamSpread = "-"; 
      $HomeTeamSpread = "+"; 
     } 
     if ($arrayAwayTeamMoneyLine > 0); { 
      $AwayTeamSpread = "+"; 
      $HomeTeamSpread = "-"; 
     } 
     echo '<tr>'; 
     echo "<td>$arrayDate[$i]</td><td><table><tr><td>$arrayARotation[$i]</td></tr><tr><td>$arrayHRotation[$i]</td></tr></table></td><td><table><tr><td>$arrayAwayTeam[$i]</td></tr><tr><td>$arrayHomeTeam[$i]</td></tr></table></td><td><table><tr><td><input type='checkbox'/> $arrayAwayTeamMoneyLine[$i]</td></tr><tr><td>$arrayHomeTeamMoneyLine[$i]</td></tr></table></td><td><table><tr><td>$AwayTeamSpread $LineStrip ($arrayAwayTeamPrice)</td></tr><tr><td>$HomeTeamSpread $LineStrip ($arrayHomeTeamPrice)</td></tr></table></td><td><table><tr><td>Over $arrayTotal</td></tr><tr><td>Under $arrayTotal</td></tr></table></td>"; 
     echo '</tr>'; 
    } 
    echo '</table>'; 
} 
?> 

這是我的php代碼的第一部分,很抱歉把它們混合起來。我在這段代碼中聲明瞭所有的數組和變量。

<?php 
require_once('db-config.php'); 
// rss page for Testing - 
$feed_url = "http://www.sportsbooks.com/lines/cgi/lines.cgi?tem=parse&sport=203&ct=text/xml&type="; 
$xml  = simplexml_load_file($feed_url); 
//Connect to mysql server 
$link  = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); 
if (!$link) { 
    die('Failed to connect to server: ' . mysql_error()); 
} 
$arrayDate    = array(
    '' 
); 
$arrayLine    = array(
    '' 
); 
$arrayLineStrip   = array(
    '' 
); 
$arrayOverPrice   = array(
    '' 
); 
$arrayUnderPrice  = array(
    '' 
); 
$arrayARotation   = array(
    '' 
); 
$arrayHRotation   = array(
    '' 
); 
$arrayAwayTeam   = array(
    '' 
); 
$arrayHomeTeam   = array(
    '' 
); 
$arrayAwayTeamPrice  = array(
    '' 
); 
$arrayHomeTeamPrice  = array(
    '' 
); 
$arrayAwayTeamMoneyLine = array(
    '' 
); 
$arrayHomeTeamMoneyLine = array(
    '' 
); 
$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  = (double) $xml->AwayTeamMoneyLine; 
$HomeTeamMoneyLine  = (double) $xml->HomeTeamMoneyLine; 
$Title     = (string) $xml->Title; 
?> 
+1

豬頭...格式化你的代碼... – jlibert

+0

這是一個用計算器我第一次..我知道我可能對編程不熟悉,可能不知道如何正確格式化代碼,但沒有理由像這樣對待新用戶。 –

+0

Per XMen,使用var_dump我可以看到我的其他值被返回爲NULL。我會做更多的研究,感謝至少有禮貌。 –

回答

1

嘗試運行的foreach像

foreach ($xml->Game as $Game=>$GameValue) { 
    // print $Game and $GameValue here to test the output ; 
} 

如果u得到數組,你可以遍歷多個

+0

感謝您的迴應,我甚至無需使用數組即可修復它!雖然會一定記住你的答案! –