The Way to Programming
The Way to Programming
I’m trying to loop through an array of data
http://pastebin.com/MfJ8scTT
and if the dates are differnt then print the date for the specified week. The code I have works for checking the time against itself, but runs into issues checking the date.
$data = simplexml_load_file("http://api.XXX.com/ffnScheduleXML.php?apiKey={getYourOwnKey:)}"); $gameDate = 1; $gameTime = 1; $gameDateTest = 0; $gameTimeTest = 0; foreach($data->Schedule->Game as $game) { if($game->attributes()->Week == $_GET['week']) { if($gameDateTest == $gameDate) { echo "\r"; }else{ echo "[COLOR=RED][B][U]".date('l, F jS', strtotime($game->attributes()->GameDate))."[/U][/B][/COLOR] : \$gameDate (".$gameDate.") | \$gameDateTest (".$gameDateTest.") \r\n"; } if ($gameTimeTest==$gameTime) { echo "\r"; }else{ date_default_timezone_set ("America/New_York"); echo'[color=darkorange][size=3]'.date("g:i A",strtotime($gameTime)).' ET / '; date_default_timezone_set ("GMT"); echo date("H:i",strtotime($gameTime)).' GMT / '; date_default_timezone_set ("Europe/Berlin"); echo date("H:i",strtotime($gameTime))." CET[/size][/color]\r\n"; } $gameTimeTest = $gameTime; $gameDateTest = $gameDate; $gameDate = $game->attributes()->GameDate; $gameTime = $game->attributes()->GameDate.' '.$game->attributes()->GameTime; echo $game->attributes()->AwayTeam." at ".$game->attributes()->HomeTeam."\r\n"; } }
Any assistance in finding a solution would be greatly helpful.
When you say you run into issues checking the date, do you mean you can’t get the code inside the first if statement to run?
If so, are you sure the content of the $_GET['week']
is in a suitable format? Try doing an 'echo $_GET['week'];'
, and also an 'echo $game->attribute()->Week;'
before the if statement to see what you’re comparing.
Sign in to your account