cowboysdude Posted February 2, 2015 Share Posted February 2, 2015 (edited) I'm trying to get this to either show "Final" or "Final Overtime" but it just continues to show "Final" even when the XML key value says Overtime... What am I missing here? Thank you! $f = ($game['q']); { if ($f == "1") $f = "1st Quarter"; else if ($f == "2") $f = "2nd Quarter"; else if ($f == "3") $f = "3rd Quarter"; else if ($f == "4") $f = "4th Quarter"; else if ($f == 'F') $f = "Final"; else if ($f == 'FO') $f = "Final Overtime"; } Edited February 2, 2015 by cowboysdude Quote Link to comment https://forums.phpfreaks.com/topic/294314-returning-xml-value-question/ Share on other sites More sharing options...
scootstah Posted February 2, 2015 Share Posted February 2, 2015 Can we see more code, and maybe a snippet of the relevant XML? It seems as if the $f == 'F' condition is always true. Quote Link to comment https://forums.phpfreaks.com/topic/294314-returning-xml-value-question/#findComment-1504618 Share on other sites More sharing options...
cowboysdude Posted February 3, 2015 Author Share Posted February 3, 2015 $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $url); // get the url contents $data = curl_exec($ch); // execute curl request curl_close($ch); $xml = simplexml_load_string($data); $someInt = (int) $xml->gms['w']; $find = array( "ARI", "ATL", 'BAL', 'BUF', 'CAR', 'CHI', 'CIN', 'CLE', 'DAL', 'DEN', 'DET', 'GB', 'HOU', 'IND', 'JAC', 'KC', 'MIA', 'MIN', 'NE', 'NO', 'NYJ', 'NYG', 'OAK', 'PHI', 'PIT', 'STL', 'SD', 'SF', 'SEA', 'TAM', 'TEN', 'WAS' ); $replace = array( "Arizona Cardinals", "Atlanta Falcons", 'Baltimore Ravens', 'Buffalo Bills', 'Carolina Panthers', 'Chicago Bears', 'Cincinnati Bengals', 'Cleveland Browns', 'Dallas Cowboys', 'Denver Broncos', 'Detroit Lions', 'Green Bay Packers', 'Houston Texans', 'Indianapolis Colts', 'Jacksonville Jaguars', 'Kansas City Chiefs', 'Miami Dolphins', 'Minnesotta Vikings', 'New England Patriots', 'New Orleans Saints', 'New York Jets', 'New York Giants', 'Oakland Raiders', 'Philadelphia Eagles', 'Pittsburgh Steelers', 'Saint Louis Rams', 'San Diego Chargers', 'San Francisco 49ers', 'Seattle Seahawks', 'Tampa Bay Buccaneers', 'Tennessee Titans', 'Washington Redskins' ); $games = array( 'REG' => array(), 'WC' => array(), 'DIV' => array(), 'CON' => array(), 'PRO' => array(), 'SB' => array() ); foreach($xml->gms->g as $game) { // if (!empty($game['vtn'])) { $games[(string) $game['gt']][] = $game; } } if (($xml->gms->g['q']) == 'F') { $final = 'Final'; } else if (($xml->gms->g['q']) == 'FO') { $final = 'Final Overtime'; } ?> <div class='smarticker6'> <ul> <?php foreach ($games as $gametype => $subgames) { foreach ($subgames as $game) { $date = DateTime::createFromFormat('Ymd', substr($game['eid'], 0, ); $gdates = $date->format('n/j/Y'); if ($game['gt'] == 'REG') { $homeTeam = str_replace($find, $replace, $game['h']); $visitingTeam = str_replace($find, $replace, $game['v']); Sure thing.. that's the entire thing Yeah I figured it was always equal to "Final" but for some reason I've locked it into that and really am confused as to where I went wrong... I suppose the smarter thing to do is to just add it to the loop at the end but I'd like it to show "Final" or "Final Overtime" or which Quarter the game is in... then just F or FO or in the case of the quarter it'll just show 1 2 3 or 4.... Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/294314-returning-xml-value-question/#findComment-1504629 Share on other sites More sharing options...
CroNiX Posted February 3, 2015 Share Posted February 3, 2015 Would be really helpful to have the XML as well, or the URL you are retrieving it from... We have nothing to test against without it. I don't see the code from your first post in the code from your last post, but in the original...the very first line doesn't make sense: $f = ($game['q']); { What's the { for at the end of that line, just before your first if()? Quote Link to comment https://forums.phpfreaks.com/topic/294314-returning-xml-value-question/#findComment-1504631 Share on other sites More sharing options...
cowboysdude Posted February 3, 2015 Author Share Posted February 3, 2015 Would be really helpful to have the XML as well, or the URL you are retrieving it from... We have nothing to test against without it. I don't see the code from your first post in the code from your last post, but in the original...the very first line doesn't make sense: $f = ($game['q']); { What's the { for at the end of that line, just before your first if()? OH sorry.. sheesh... sometimes I get tunnel vision... $type = $params->get('type'); if ($type == '0') { $url='http://www.nfl.com/liveupdate/scorestrip/ss.xml'; } else { $url='http://www.nfl.com/liveupdate/scorestrip/postseason/ss.xml'; } Right now returns this: <ss> <gms w="22" y="2014" t="POST" gd="1" bf="0" bph="12"> <g eid="2015010301" gsis="56492" d="Sat" t="8:15" q="F" htn="Pittsburgh Steelers" hnn="steelers" h="PIT" hs="17" vtn="Baltimore Ravens" vnn="ravens" v="BAL" vs="30" n="NBC" rz="0" ga="" o="1" gt="WC"/> <g eid="2015010400" gsis="56493" d="Sun" t="1:05" q="F" htn="Indianapolis Colts" hnn="colts" h="IND" hs="26" vtn="Cincinnati Bengals" vnn="bengals" v="CIN" vs="10" n="CBS" rz="0" ga="" o="2" gt="WC"/> <g eid="2015011000" gsis="56495" d="Sat" t="4:35" q="F" htn="New England Patriots" hnn="patriots" h="NE" hs="35" vtn="Baltimore Ravens" vnn="ravens" v="BAL" vs="31" n="NBC" rz="0" ga="" o="3" gt="DIV"/> <g eid="2015011101" gsis="56498" d="Sun" t="4:40" q="F" htn="Denver Broncos" hnn="broncos" h="DEN" hs="13" vtn="Indianapolis Colts" vnn="colts" v="IND" vs="24" n="CBS" rz="0" ga="" o="4" gt="DIV"/> <g eid="2015011801" gsis="56500" d="Sun" t="6:50" q="F" htn="New England Patriots" hnn="patriots" h="NE" hs="45" vtn="Indianapolis Colts" vnn="colts" v="IND" vs="7" n="CBS" rz="0" ga="" o="5" gt="CON"/> <g eid="2015011800" gsis="56499" d="Sun" t="3:05" q="FO" htn="Seattle Seahawks" hnn="seahawks" h="SEA" hs="28" vtn="Green Bay Packers" vnn="packers" v="GB" vs="22" n="FOX" rz="0" ga="" o="6" gt="CON"/> <g eid="2015011100" gsis="56497" d="Sun" t="1:05" q="F" htn="Green Bay Packers" hnn="packers" h="GB" hs="26" vtn="Dallas Cowboys" vnn="cowboys" v="DAL" vs="21" n="FOX" rz="0" ga="" o="7" gt="DIV"/> <g eid="2015011001" gsis="56496" d="Sat" t="8:15" q="F" htn="Seattle Seahawks" hnn="seahawks" h="SEA" hs="31" vtn="Carolina Panthers" vnn="panthers" v="CAR" vs="17" n="FOX" rz="0" ga="" o="8" gt="DIV"/> <g eid="2015010401" gsis="56494" d="Sun" t="4:40" q="F" htn="Dallas Cowboys" hnn="cowboys" h="DAL" hs="24" vtn="Detroit Lions" vnn="lions" v="DET" vs="20" n="FOX" rz="0" ga="" o="9" gt="WC"/> <g eid="2015010300" gsis="56491" d="Sat" t="4:35" q="F" htn="Carolina Panthers" hnn="panthers" h="CAR" hs="27" vtn="Arizona Cardinals" vnn="cardinals" v="ARI" vs="16" n="ESPN" rz="0" ga="" o="10" gt="WC"/> <g eid="2015012500" gsis="56501" d="Sun" t="8:00" q="F" htn="Team Cris Carter" hnn="team carter" h="CRT" hs="28" vtn="Team Michael Irvin" vnn="team irvin" v="IRV" vs="32" n="ESPN" rz="0" ga="" o="11" gt="PRO"/> <g eid="2015020100" gsis="56502" d="Sun" t="6:30" q="F" htn="Seattle Seahawks" hnn="seahawks" h="SEA" hs="24" vtn="New England Patriots" vnn="patriots" v="NE" vs="28" n="NBC" rz="0" ga="" o="12" gt="SB"/> </gms> Quote Link to comment https://forums.phpfreaks.com/topic/294314-returning-xml-value-question/#findComment-1504632 Share on other sites More sharing options...
scootstah Posted February 3, 2015 Share Posted February 3, 2015 So, I'm a little confused. Here you are looping over $xml->gms->g foreach($xml->gms->g as $game) { // if (!empty($game['vtn'])) { $games[(string) $game['gt']][] = $game; } }But here (right below it) you are not: if (($xml->gms->g['q']) == 'F') { $final = 'Final'; } else if (($xml->gms->g['q']) == 'FO') { $final = 'Final Overtime'; }You are only comparing the last index of $xml->gms->g (since you just iterated over it), which happens to be "F". I can't see what you're trying to do with $final, but I think you got some flawed logic in there. 1 Quote Link to comment https://forums.phpfreaks.com/topic/294314-returning-xml-value-question/#findComment-1504636 Share on other sites More sharing options...
cowboysdude Posted February 3, 2015 Author Share Posted February 3, 2015 So, I'm a little confused. Here you are looping over $xml->gms->g foreach($xml->gms->g as $game) { // if (!empty($game['vtn'])) { $games[(string) $game['gt']][] = $game; } }But here (right below it) you are not: if (($xml->gms->g['q']) == 'F') { $final = 'Final'; } else if (($xml->gms->g['q']) == 'FO') { $final = 'Final Overtime'; }You are only comparing the last index of $xml->gms->g (since you just iterated over it), which happens to be "F". I can't see what you're trying to do with $final, but I think you got some flawed logic in there. Yeah I do... I'm gonna let it slide for now... The first one is looping through...'gt' is game type... WC, CON, DIV, SB, PRO they are the playoff games... WC = Wildcard..etc... I did that to put them in the order I wanted them to show.. It would go through and show 2 WC games.. then 2 CON game...then DIV.. Then Pro... Then SB...then back to CON.. then ending at WC I wanted all the same game types to show at once in the correct order... WC DIV CON PRO SB That is the order they are played in... But at the moment I have changed my thinking... Yes I want to show the final or final overtime but that 'q' can also show game quarter 1 2 3 or 4 so I have to set it up for the regular season you know some games are on at 1 some at 4 so that way it will show Final or Final Overtime for finished games and the Quarter they're in for current games.... I'm a bit tired now so I hope I'm not flappin' like a ducks butt right now LOL Quote Link to comment https://forums.phpfreaks.com/topic/294314-returning-xml-value-question/#findComment-1504658 Share on other sites More sharing options...
scootstah Posted February 3, 2015 Share Posted February 3, 2015 Right, but the 'q' part is outside of the foreach loop. So, you're only looking at the data from one node. Quote Link to comment https://forums.phpfreaks.com/topic/294314-returning-xml-value-question/#findComment-1504659 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.