Hellp with xml and mysql php script

can someone help the prob is this is part of my script the script sends to a data base ok but send all the products_id ok but the products_model code are the same

products_id products_model
12796 0 bb2018
12805 0 bb2018
13719 0 bb2018

this i part of the xml file this to show the stucher

<STOREITEMS>
<CREATED value="Fri Feb 22 1:01:02 GMT 2013">
<CATEGORY id="442" name=" > test">
<PRODUCT ITEM="12796">
<NAME>test1</NAME>
<MODEL>bb2018</MODEL>
<PRICE>2.28</PRICE>
<RRP>3.99</RRP>
<THUMB>bb2018s.jpg</THUMB>
<IMAGE>bb2018.jpg</IMAGE>
<DESCRIPTION>
foreach($xml->xpath('//PRODUCT/@ITEM') as $productitemid){
foreach($xml->CREATED->CATEGORY->PRODUCT as $product)

                                        
                                           
mysql_query("INSERT INTO products (products_id,products_model) VALUES ('$productitemid','$product')");
}

foreach product, then retreive the relevant information about each one.

thanks for that works ok
got this far i dont know how to wright the code to id number out of the PRODUCT ITEM
part of the xml file

foreach($xml->CREATED->CATEGORY->PRODUCT as $product){

$productitemid   = $product->xpath(".//PRODUCT[ITEM='']");



$title   = $product->MODEL;
$rrp   = $product->RRP;

mysql_query("INSERT INTO products (products_id,products_model,products_price) VALUES ('$productitemid','$title','$rrp')");

It’s been a while since i did XML transitions, but if i’m not mistaken, $product->attributes() should return an array containing an element “ITEM”, so…
$atts = $product->attributes();
$productid = $atts[‘ITEM’];

thank you so much starlion
works a treet

i got this far but the prob is now is only reads the products in the first category and not the next categorys


foreach($xml->CREATED->CATEGORY->PRODUCT as $product){

$atts = $product->attributes();
 $productitemid = $atts['ITEM'];

$title   = $product->MODEL;
$rrp   = $product->RRP;
$productsdescription   = $product->DESCRIPTION;
$prodname   = $product->NAME;



 echo  $productitemid.' - ' ;


 // echo $product->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')");



foreach($xml->CREATED->CATEGORY as $categorie)


$attscats = $categorie->attributes();
 $id = $attscats['id'];
 $name = $attscats['name'];

mysql_query("INSERT INTO categories_description (categories_id,categories_name) VALUES ('$id','$name')");
 mysql_query("INSERT INTO products_to_categories (products_id,categories_id) VALUES ('$productitemid','$id')");
mysql_query("INSERT INTO categories (categories_id) VALUES ('$id')");






}


foreach($xml->CREATED->CATEGORY->PRODUCT->ATTRIBUTES as $productsoptions)

$productsoptionsid = $productsoptions->attributes();
 $optionsid = $productsoptionsid['ATTRIBUTEID'];
$optionsname = $productsoptionsid['NAME'];

mysql_query("INSERT INTO products_options (products_options_id,products_options_name) VALUES ('$optionsid','$optionsname')");


foreach($xml->CREATED->CATEGORY->PRODUCT->ATTRIBUTEVALUES as $optionsvalues)
$productsoptionsvalues = $optionsvalues->attributes();
$productsoptionsvaluesid = $productsoptionsvalues['VALUE'];
$productsoptionsvaluesname = $productsoptionsvalues['TITLE'];



mysql_query("INSERT INTO products_options_values (products_options_values_id,products_options_values_name) VALUES ('$productsoptionsvaluesid','$productsoptionsvaluesname')");
mysql_query("INSERT INTO products_attributes (products_attributes_id,products_id,options_id,options_values_id) VALUES ('$productitemid','$productitemid','$optionsid','$productsoptionsvaluesid')");




mysql_query("INSERT INTO products (products_id,products_model) VALUES ('$n->ITEM')");
mysql_query("INSERT INTO products (products_id,products_model) VALUES ('$productitemid','$product->MODEL')");
}

i have many categorys in my xml how do i get to read all the products it only reads the frist category
thanks

foreach($xml->CREATED->CATEGORY as $product){

$atts = $product->PRODUCT->attributes();
 $productitemid = $atts['ITEM'];

$title   = $product->MODEL;
$rrp   = $product->RRP;
$productsdescription   = $product->DESCRIPTION;
$prodname   = $product->NAME;



 echo  $productitemid.' - ' ;


 // echo $product->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')");
}

What does your XML look like?

The xml file

<?xml version="1.0" encoding="iso-8859-1"?>
<STOREITEMS>
<CREATED value="Fri Feb 22 1:01:02 GMT 2013">
<CATEGORY id="441" name=" > test1">
<PRODUCT ITEM="12796">
<NAME>test1</NAME>
<MODEL>bb2018</MODEL>
<PRICE>2.28</PRICE>
<RRP>3.99</RRP>
<THUMB>bb2018s.jpg</THUMB>
<IMAGE>bb2018.jpg</IMAGE>
<DESCRIPTION>
test1
</DESCRIPTION>
<POWER/>
<SIZE/>
<ATTRIBUTES NAME="Size" ATTRIBUTEID="2">
<ATTRIBUTEVALUES VALUE="16" TITLE="Small" PRICEADJUST="0.00"/>
<ATTRIBUTEVALUES VALUE="17" TITLE="Medium" PRICEADJUST="0.00"/>
<ATTRIBUTEVALUES VALUE="18" TITLE="Large" PRICEADJUST="0.00"/>
</ATTRIBUTES>
</PRODUCT>
<CATEGORY id="442" name=" > test2">
<PRODUCT ITEM="12805">
<NAME>test2</NAME>
<MODEL>bb2034</MODEL>
<PRICE>0.58</PRICE>
<RRP>1.50</RRP>
<THUMB>bb2034s.jpg</THUMB>
<IMAGE>bb2034.jpg</IMAGE>
<DESCRIPTION>
test2
</DESCRIPTION>
<POWER/>
<SIZE/>
</PRODUCT>
<CATEGORY id="4423" name=" > test3">
<PRODUCT ITEM="13719">
<NAME>test3?</NAME>
<MODEL>BCPG02</MODEL>
<PRICE>2.83</PRICE>
<RRP>4.95</RRP>
<THUMB>bcg02s.jpg</THUMB>
<IMAGE>bcpg02.jpg</IMAGE>
<DESCRIPTION>
test3
</DESCRIPTION>
</PRODUCT>
</CATEGORY>
</CREATED>
</STOREITEMS>

Your XML isn’t properly formatted. You are missing the closing tags for CATEGORY multiple times (see the indented version below).

<?xml version="1.0" encoding="iso-8859-1"?>
<STOREITEMS>
	<CREATED value="Fri Feb 22 1:01:02 GMT 2013">
		<CATEGORY id="441" name=" > test1">
			<PRODUCT ITEM="12796">
				<NAME>test1</NAME>
				<MODEL>bb2018</MODEL>
				<PRICE>2.28</PRICE>
				<RRP>3.99</RRP>
				<THUMB>bb2018s.jpg</THUMB>
				<IMAGE>bb2018.jpg</IMAGE>
				<DESCRIPTION>
				test1
				</DESCRIPTION>
				<POWER/>
				<SIZE/>
				<ATTRIBUTES NAME="Size" ATTRIBUTEID="2">
					<ATTRIBUTEVALUES VALUE="16" TITLE="Small" PRICEADJUST="0.00"/>
					<ATTRIBUTEVALUES VALUE="17" TITLE="Medium" PRICEADJUST="0.00"/>
					<ATTRIBUTEVALUES VALUE="18" TITLE="Large" PRICEADJUST="0.00"/>
				</ATTRIBUTES>
			</PRODUCT>
		<CATEGORY id="442" name=" > test2">
			<PRODUCT ITEM="12805">
				<NAME>test2</NAME>
				<MODEL>bb2034</MODEL>
				<PRICE>0.58</PRICE>
				<RRP>1.50</RRP>
				<THUMB>bb2034s.jpg</THUMB>
				<IMAGE>bb2034.jpg</IMAGE>
				<DESCRIPTION>
				test2
				</DESCRIPTION>
				<POWER/>
				<SIZE/>
			</PRODUCT>
		<CATEGORY id="4423" name=" > test3">
			<PRODUCT ITEM="13719">
				<NAME>test3?</NAME>
				<MODEL>BCPG02</MODEL>
				<PRICE>2.83</PRICE>
				<RRP>4.95</RRP>
				<THUMB>bcg02s.jpg</THUMB>
				<IMAGE>bcpg02.jpg</IMAGE>
				<DESCRIPTION>
				test3
				</DESCRIPTION>
			</PRODUCT>
		</CATEGORY>
	</CREATED>
</STOREITEMS>

hi
yes i cut and paste it from the orignal xml and for got to put them in i use the orignal to try it wich correct
thanks