0

I cannot seem to echo the contents of my arrays. For some reason, only the 2nd value from all of my arrays are being displayed. Any help would be greatly appreciated. The php code is as follows:

<?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>';
}
?>

This is the 1st part of my php code, sorry to mix them up. I declare all of my arrays and variables in this section of the coding.

<?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;
?>
6
  • This is my first time using stackoverflow.. I understand I may be new to programming, may not know how to properly format code yet, but there's no reason to treat a new user like this. Commented Oct 26, 2012 at 4:40
  • Per XMen, using var_dump I can see that my other values are being returned as NULL. I'll do some more research, thanks for at least being courteous. Commented Oct 26, 2012 at 4:41
  • @BlaineHurtado: I understand, and apologize. Let me see if I can find anything wrong with your code. Welcome to SO! In your code where is $arrayDate, $arrayARotation etc getting created? Commented Oct 26, 2012 at 4:49
  • @Raidenace thanks for your hospitality. I joined this forum to learn and hopefully give back one day! I understand how most members who frequent might mix up my lack of skill for someone looking for a handout, I see it a lot :/ Sorry I forgot to add my 1st part of php code! Commented Oct 26, 2012 at 4:56
  • @BlaineHurtado welcome to SO. Formatting your code properly is pretty important for readability and debugging, and there's no reason to not do it even when you're new. I've done it for you in this question. Commented Oct 26, 2012 at 5:21

1 Answer 1

1

Try to run foreach like

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

if u get array you can iterate more

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the response, I ended up fixing it without even having to use an array! Will definitely keep your answer in mind though!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.