Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I get to read all the products from XML
    primarykey
    data
    text
    <p>I have many categories in my XML file. How can I read all the products in it?</p> <p>It only reads the first category. I am including the xml file for you to look at. Here is the PHP code I'm using: </p> <pre><code> //get products from xml file foreach($xml-&gt;CREATED-&gt;CATEGORY as $product){ $atts = $product-&gt;PRODUCT-&gt;attributes(); $productitemid = $atts['ITEM']; $title = $product-&gt;MODEL; $rrp = $product-&gt;RRP; $productsdescription = $product-&gt;DESCRIPTION; $prodname = $product-&gt;NAME; echo $productitemid.' - ' ; // echo $product-&gt;id.' - '; mysql_query("INSERT INTO products (products_id,products_model,products_price,products_status) VALUES ('$productitemid','$title','$rrp','1')"); mysql_query("INSERT INTO products_description (products_id,products_name,products_description) VALUES ('$productitemid','$prodname','$productsdescription')"); } </code></pre> <p>And here is the XML structure:</p> <pre><code> &lt;?xml version="1.0" encoding="iso-8859-1"?&gt; &lt;STOREITEMS&gt; &lt;CREATED value="Fri Feb 22 1:01:02 GMT 2013"&gt; &lt;CATEGORY id="441" name=" &gt; test1"&gt; &lt;PRODUCT ITEM="12796"&gt; &lt;NAME&gt;test1&lt;/NAME&gt; &lt;MODEL&gt;bb2018&lt;/MODEL&gt; &lt;PRICE&gt;2.28&lt;/PRICE&gt; &lt;RRP&gt;3.99&lt;/RRP&gt; &lt;THUMB&gt;bb2018s.jpg&lt;/THUMB&gt; &lt;IMAGE&gt;bb2018.jpg&lt;/IMAGE&gt; &lt;DESCRIPTION&gt; test1 &lt;/DESCRIPTION&gt; &lt;POWER/&gt; &lt;SIZE/&gt; &lt;ATTRIBUTES NAME="Size" ATTRIBUTEID="2"&gt; &lt;ATTRIBUTEVALUES VALUE="16" TITLE="Small" PRICEADJUST="0.00"/&gt; &lt;ATTRIBUTEVALUES VALUE="17" TITLE="Medium" PRICEADJUST="0.00"/&gt; &lt;ATTRIBUTEVALUES VALUE="18" TITLE="Large" PRICEADJUST="0.00"/&gt; &lt;/ATTRIBUTES&gt; &lt;/PRODUCT&gt; &lt;CATEGORY id="442" name=" &gt; test2"&gt; &lt;PRODUCT ITEM="12805"&gt; &lt;NAME&gt;test2&lt;/NAME&gt; &lt;MODEL&gt;bb2034&lt;/MODEL&gt; &lt;PRICE&gt;0.58&lt;/PRICE&gt; &lt;RRP&gt;1.50&lt;/RRP&gt; &lt;THUMB&gt;bb2034s.jpg&lt;/THUMB&gt; &lt;IMAGE&gt;bb2034.jpg&lt;/IMAGE&gt; &lt;DESCRIPTION&gt; test2 &lt;/DESCRIPTION&gt; &lt;POWER/&gt; &lt;SIZE/&gt; &lt;/PRODUCT&gt; &lt;CATEGORY id="4423" name=" &gt; test3"&gt; &lt;PRODUCT ITEM="13719"&gt; &lt;NAME&gt;test3?&lt;/NAME&gt; &lt;MODEL&gt;BCPG02&lt;/MODEL&gt; &lt;PRICE&gt;2.83&lt;/PRICE&gt; &lt;RRP&gt;4.95&lt;/RRP&gt; &lt;THUMB&gt;bcg02s.jpg&lt;/THUMB&gt; &lt;IMAGE&gt;bcpg02.jpg&lt;/IMAGE&gt; &lt;DESCRIPTION&gt; test3 &lt;/DESCRIPTION&gt; &lt;/PRODUCT&gt; &lt;/CATEGORY&gt; &lt;/CREATED&gt; &lt;/STOREITEMS&gt; </code></pre> <p>i have done it like this it works. How do i get the products from the categorys then go to the next cateory and get the next porducts the dabase needs them sequence</p> <pre><code> //i have done it like this it works $doc = new DOMDocument(); $var = $doc-&gt;load('shop.xml'); $root = $doc-&gt;documentElement; //root node $items = $doc-&gt;getElementsByTagName('PRODUCT'); $cat = $doc-&gt;getElementsByTagName('CATEGORY'); foreach ($cat as $cats){ foreach ($items as $bar) if ($categoriesid == $b) $productsid = $bar-&gt;getAttribute('ITEM'); $modelcode = $bar-&gt;getElementsByTagName('MODEL')-&gt;item(0)-&gt;nodeValue; $rrp = $bar-&gt;getElementsByTagName('RRP')-&gt;item(0)-&gt;nodeValue; $productsdescription = $bar-&gt;getElementsByTagName('DESCRIPTION')-&gt;item(0)-&gt;nodeValue; $prodname = $bar-&gt;getElementsByTagName('NAME')-&gt;item(0)-&gt;nodeValue; $categoriesid = $cats-&gt;getAttribute('id'); $categoriesname = $cats-&gt;getAttribute('name'); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload