alwoodman Posted March 3, 2009 Share Posted March 3, 2009 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 Link to comment https://forums.phpfreaks.com/topic/147780-solved-so-close-yet-so-far-phpxml-simplexml-issue-looping/ Share on other sites More sharing options...
rhodesa Posted March 3, 2009 Share Posted March 3, 2009 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>"; } } } ?> Link to comment https://forums.phpfreaks.com/topic/147780-solved-so-close-yet-so-far-phpxml-simplexml-issue-looping/#findComment-775783 Share on other sites More sharing options...
alwoodman Posted March 4, 2009 Author Share Posted March 4, 2009 ah ha...ive briefly tested it and it looks to be doing what i had hoped...much appreciated. Lee Link to comment https://forums.phpfreaks.com/topic/147780-solved-so-close-yet-so-far-phpxml-simplexml-issue-looping/#findComment-776133 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.