i73 Posted May 13, 2014 Share Posted May 13, 2014 Hey guys I am trying to read my xml file and itterate through the list. I am having trouble. <?xml version="1.0" encoding="UTF-8"?> <stock> <itemPlace id="1"> <name>null</name> <image>null</image> <wholeSale>44</wholeSale> <retailPrice>null</retailPrice> <quantity>null</quantity> <location>null</location> <color>null</color> <size>null</size> <weight>null</weight> <description>null</description> <itemType>null</itemType> <date>null</date> </itemPlace> <itemPlace id="2"> <name>null</name> <image>null</image> <wholeSale>55</wholeSale> <retailPrice>null</retailPrice> <quantity>null</quantity> <location>null</location> <color>null</color> <size>null</size> <weight>null</weight> <description>null</description> <itemType>null</itemType> <date>null</date> </itemPlace> </stock> <?php $xml = simplexml_load_file('stock.xml'); foreach ($xml->xpath('itemPlace') as $eq) { echo "<p><a class='inline' href=\"#inline_content\"> {$eq->name}</a></p>"; echo '<br>'; echo " <div style='display:none'>"; echo " <div id='inline_content' style='padding:10px; background:#fff;'>"; echo " <p>"; echo " <strong>{$eq->wholeSale}</strong>"; echo "</div></div>"; Is there a way I can look up the object through the itemPlace id="#" and call out the parameters of the item? Like the name price, etc? I know how to mySQL query but not XML, and this is a project that needs to use xml... FML..I have been looking for a few hours so any help would be appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/288449-php-and-xml-database-trouble/ Share on other sites More sharing options...
Solution requinix Posted May 13, 2014 Solution Share Posted May 13, 2014 You can do a lookup with xpath: foreach ($xml->xpath("//itemPlace[@id=123]") as $eq) // look for itemPlace with id=123As for the "parameters", you're already doing it with $eq->wholeSale. Quote Link to comment https://forums.phpfreaks.com/topic/288449-php-and-xml-database-trouble/#findComment-1479308 Share on other sites More sharing options...
i73 Posted May 17, 2014 Author Share Posted May 17, 2014 You can do a lookup with xpath: foreach ($xml->xpath("//itemPlace[@id=123]") as $eq) // look for itemPlace with id=123As for the "parameters", you're already doing it with $eq->wholeSale. Thanks, yeah I realized as I fixed the problem. Quote Link to comment https://forums.phpfreaks.com/topic/288449-php-and-xml-database-trouble/#findComment-1479855 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.