Jump to content

It works but...


cowboysdude

Recommended Posts

With a TON of help from you guys already it's working but I do have one thing that I just need to figure out to clean it all up...

echo $games['htn']," ",$games['hs']," VS ",$games['vtn']," ",$games['vs']," on ",$games['d']," at ",$games['t'];

 This is returning what I need perfectly except if an object is empty it's also showing that..  for example...

 

Pittsburgh Steelers 0 VS Baltimore Ravens 0 on Sat at 8:15  --- is what I want to show...

 

shows up great then the next line will show an empty set because the games are not known until other games are played so I also get this:

 

0 VS 0 on Jan 18 at 3:05 

and

Seattle Seahawks 0 VS 0 on Jan 10 at 8:15

 

What can I do to make this not show up?

$xml = simplexml_load_string($data);
// print_r($xml);  
 
foreach($xml->gms->g as $games)
{
echo "<div class='button blue'>";

echo $games['htn']," ",$games['hs']," VS ",$games['vtn']," ",$games['vs']," on ",$games['d']," at ",$games['t'];
echo "</div>";

 
}

This is what I have and it's working with a lot of help from you guys... I just need to clean it up so I can show only games that have two teams listed.. 

 

Thanks again everyone!!

Link to comment
https://forums.phpfreaks.com/topic/293610-it-works-but/
Share on other sites

 

foreach($xml->gms->g as $games)
{
    //Skip if either team name is empty
    if(empty($games['htn']) || empty($games['vtn'])) { continue; }
 
    //If both scores are 0, don't show them (game hasn't been played)
    if($games['hs']==0 && $games['hs']==0)
    {
        $games['hs'] = '';
        $games['vs'] = '';
    }
    echo "<div class='button blue'>";
    echo "{$games['htn']} {$games['hs']} VS {$games['vtn']} {$games['vs']} on {$games['d']} at {$games['t']}";
    echo "</div>";
}
Link to comment
https://forums.phpfreaks.com/topic/293610-it-works-but/#findComment-1501578
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.