Jump to content

Recommended Posts

Currently what I have is this:

$url="http://www.nfl.com/liveupdate/scorestrip/postseason/ss.xml";
  $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);
  foreach($xml->gms->g as $games)
    {
  	if(!empty($games['vtn']))
    {
     if ((($games['gt']) =='WC') && (($games['q'])== 'F')) {
 	 	echo "<li data-subcategory='Final Scores' data-category='Wild Card Games' data-color='1979ab'><a href='#'>",$games['htn']," ",$games['hs'],"  ",$games['vtn'],"  ",$games['vs'],"  Final</a></li>";
 	 		 }
     if (($games['gt']) =='DIV') {
 		echo "<li data-subcategory='Final Scores' data-category='Divisional Games' data-color='14ab05'><a href='#'>",$games['htn']," ",$games['hs'],"  ",$games['vtn'],"  ",$games['vs'],"  ",$games['d']," at ",$games['t'], "</a></li>";
 	 }
 	 if (($games['gt']) == 'CON') {
 echo "<li data-subcategory='Conference Games' data-category='Sunday' data-color='000000'><a href='#'>",$games['htn']," ",$games['hs'],"  ",$games['vtn'],"  ",$games['vs'],"  ",$games['d']," at ",$games['t'], "</a></li>";
 	  }
    }
  }

It works great, Thanks to some help!

 

The only thing I'd like to do now is have the output be a little more inline ...currently it reads the xml line by line and outputs the each item.. the order is the problem...

It does this:

 

Wild Card game

Wild Card game

Div game

Div game

Conference game

Conference game

Div game

Div game

Wild Card game

Wild Card game

 

I'd like it to output one type at a time....basically grouping all types together..

WC game

Div game

Conference game

 

I continue to learn but this one is stumping me... 

I did get an idea from someone but not sure how to carry this one out...

 

 

Instead of outputting it directly you could just add it to an array in the first loop

So for each game you do
$games[$type][] = $game;

Then you can add another loop (for output) where you will have them sorted

 

Just not sure how to handle that.. I'm feeling a bit lost at the moment...

 

Is this in reference to putting $games[$type] = $game in place of foreach($xml->gms->g as $games)?

 

I guess the second part has me lost as well adding another loop for output... needing to be sorted because each output is styled differently

 

I guess I'm just not understanding....  can anyone clarify for me please?

 

Thanks everyone!

Link to comment
https://forums.phpfreaks.com/topic/293972-something-easier/
Share on other sites

 

 

WOW Thank you BIG TIME... that is very clear and I really like that information!!!  Great new way for me to learn!!!

 

Thank you sooooooooo much!!   Not that anyone wants to know but I'll let you know the results!!! :)

Link to comment
https://forums.phpfreaks.com/topic/293972-something-easier/#findComment-1503108
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.