Jump to content

[SOLVED] So close yet so far (PHP/XML simplexml issue looping)


alwoodman

Recommended Posts

Hi Im trying to loop through an XML file which has

3 PrimaryCategories

unlimited CategoryList

and unlimited EventList

 

The code below works to a degree in that it will loop through all the elements but it pulls out the same category and event data each time instead of skipping onto the next category List

 

This is what i have so far:

 

<?php
$s = simplexml_load_file('../events.xml');

// 3 primary categories

	foreach ($s->PrimaryCategory as $PrimaryCategory) {		

		foreach ($s->PrimaryCategory->CategoryList as $CategoryList) {

			foreach ($s->PrimaryCategory->CategoryList->EventList as $EventList) {

					print $EventList->EventID . $EventList->EventName ."</br>";


			}
			unset($EventList);
		}
		unset($CategoryList);
	}
	unset($PrimaryCategory);

?>

 

This is the XML format

 

<VLinks>
−
<PrimaryCategory>
<PrimaryCategoryID/>
<PrimaryCategoryName/>
<PrimaryCategoryURL/>
−
<CategoryList>
<CategoryID/>
<CategoryName/>
<CategoryURL/>
<CategoryImageURL/>
<CategoryDescription/>
−
<EventList>
<EventID/>
<EventName/>
<EventDate/>
<EventURL/>
<VenueName/>
<VenueCity/>
<VenueAddress/>
<VenueState/>
<VenueCountryCode/>
<VenuePostCode/>
<MinCurrentPrice/>
<MaxCurrentPrice/>
<TicketCount/>
<PresaleDate/>
<OnSaleDate/>
<SoldOutDate/>
</EventList>
</CategoryList>
</PrimaryCategory>
</VLinks>

 

The problem at the moment is the results look like...

 

186991Billy Elliot - The Musical

186992Billy Elliot - The Musical

186993Billy Elliot - The Musical

186994Billy Elliot - The Musical

186995Billy Elliot - The Musical

186996Billy Elliot - The Musical

186997Billy Elliot - The Musical

186998Billy Elliot - The Musical

186999Billy Elliot - The Musical

135279Billy Elliot (Matinee)

135280Billy Elliot (Matinee)

135281Billy Elliot (Matinee)

135282Billy Elliot (Matinee)

135283Billy Elliot (Matinee)

135284Billy Elliot (Matinee)

135285Billy Elliot (Matinee)

135286Billy Elliot (Matinee)

135287Billy Elliot (Matinee)

135288Billy Elliot (Matinee)

135289Billy Elliot (Matinee)

135290Billy Elliot (Matinee)

 

thanks

 

Lee

try this:

<?php
      $s = simplexml_load_file('../events.xml');
      foreach ($s->PrimaryCategory as $PrimaryCategory) {      
         foreach ($PrimaryCategory->CategoryList as $CategoryList) {
            foreach ($CategoryList->EventList as $EventList) {
                  print $EventList->EventID . $EventList->EventName ."</br>";
            }
         }
      }
?>

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.