shanejeffery86 Posted July 22, 2008 Share Posted July 22, 2008 Hey there guys. I hope that I have come to the right place for this answer. Been racking my brain lately trying to figure out how this will be done. Anyways, what I need to do is this: I have a foreach loop that is running through the data received from an XML feed. The XML feed has the basic setup of <element><subelement>. It does not go much deeper into the schema than that. What I have found that is for one of the elements, it sometimes has 3 or more <subelement>'s. Each of those <subelements> have the same element name -- i.e. Speakers1, Speakers2, Speakers3. What I need to code for is this: I need to make a loop within the foreach loop that grabs each of the Speakers in that element and puts them into an array or something of that nature. When that loop has run out of Speakers in the array, the loop will end. In this loop, there will be an INSERT INTO SQL statement that will be taking the speaker data and tossing it into the database. That is the basic of what needs to happen. Any help would be greatly appreciated. Just trying a blank on how I would structure this. Thanks. Link to comment https://forums.phpfreaks.com/topic/116041-php-and-xml-grabbing-multiple-sub-elements/ Share on other sites More sharing options...
DarkWater Posted July 22, 2008 Share Posted July 22, 2008 Use SimpleXML. I'd have to say it makes it rather simple to do. (pun) Link to comment https://forums.phpfreaks.com/topic/116041-php-and-xml-grabbing-multiple-sub-elements/#findComment-596679 Share on other sites More sharing options...
shanejeffery86 Posted July 22, 2008 Author Share Posted July 22, 2008 It is already in a SimpleXML format. Right now, when I do my print/die to see what is in the variable, it just shows one record, when it needs to show 3 or more. <Speaker> --><Speaker1> ----><Data for speaker1> --><Speaker2> ----><Data for speaker2> --><Speaker3> ----><Data for speaker3> etc... I need to make it so that one variable can hold all three of those subelements and be able to run through them in a loop. The loop part will be easy. I just need to get the subelement data into the same variable. I tried an array, but I am sure that I am not putting it together right. $variable = array($xml->Speaker) -- I know that that is not working, but I am not sure how else to structure it due to the XML. Thanks. Link to comment https://forums.phpfreaks.com/topic/116041-php-and-xml-grabbing-multiple-sub-elements/#findComment-596688 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.