Jump to content

It works but...


Go to solution Solved by Psycho,

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!!

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

  • Solution

 

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>";
}
  • Like 1
Link to comment
https://forums.phpfreaks.com/topic/293610-it-works-but/#findComment-1501578
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.