SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Member
    Join Date
    Feb 2013
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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

    Code XML:
    <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>
    Code PHP:
    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')");
    }

  2. #2
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,747
    Mentioned
    65 Post(s)
    Tagged
    0 Thread(s)
    foreach product, then retreive the relevant information about each one.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  3. #3
    SitePoint Member
    Join Date
    Feb 2013
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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


    Code PHP:
    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')");

  4. #4
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,747
    Mentioned
    65 Post(s)
    Tagged
    0 Thread(s)
    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'];
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  5. #5
    SitePoint Member
    Join Date
    Feb 2013
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thank you so much starlion
    works a treet

  6. #6
    SitePoint Member
    Join Date
    Feb 2013
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i got this far but the prob is now is only reads the products in the first category and not the next categorys




    Code PHP:
    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')");
    }

  7. #7
    SitePoint Member
    Join Date
    Feb 2013
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    It only reads the frist category

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

    Code PHP:
    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')");
    }

  8. #8
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    4,823
    Mentioned
    142 Post(s)
    Tagged
    0 Thread(s)
    What does your XML look like?
    Be sure to congratulate xMog on earning April's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  9. #9
    SitePoint Member
    Join Date
    Feb 2013
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The xml file


    Code XML:
    <?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>

  10. #10
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    4,823
    Mentioned
    142 Post(s)
    Tagged
    0 Thread(s)
    Your XML isn't properly formatted. You are missing the closing tags for CATEGORY multiple times (see the indented version below).
    Code XML:
    <?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>
    Be sure to congratulate xMog on earning April's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  11. #11
    SitePoint Member
    Join Date
    Feb 2013
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •