Note that there are some explanatory texts on larger screens.

plurals
  1. POForeach loop prob in php script for mysql
    primarykey
    data
    text
    <p>i am trying to loop in a xml file now it wrights to the data dase ok but only one record show up i had some help from this site what was very helpfull and fixed the prob for one foreach stapmmet but now i have more of them it is back to only one being input in the data base i am at loss to what to do now thank you <pre><code>ini_set('display_errors','On'); echo "starting"; //mysql connection $con2 = mysql_connect("localhost","user","pass"); if (!$con2) { die('Could not connect: ' . mysql_error()); } $selectdb = mysql_select_db("database", $con2); if (!$selectdb) { die('Database not used: ; ' . mysql_error()); } echo "connected to DB&lt;br /&gt;&lt;br /&gt;"; //simplexml load xml file { $xml = simplexml_load_file('myproduct.xml'); mysql_query('DELETE FROM products WHERE 1'); mysql_query('DELETE FROM categories_description WHERE 1'); mysql_query('DELETE FROM products_to_categories WHERE 1'); } { foreach($xml-&gt;CREATED-&gt;CATEGORY-&gt;PRODUCT as $product); foreach($xml-&gt;xpath('//PRODUCT/@ITEM') as $productitemid); foreach($xml-&gt;CREATED-&gt;CATEGORY as $categories); foreach($xml-&gt;xpath('//CATEGORY/@id') as $id); foreach($xml-&gt;xpath('//CATEGORY/@name') as $name); mysql_query("INSERT INTO products (products_model,products_id) VALUES ('$product- &gt;MODEL','$productitemid')"); mysql_query("INSERT INTO products_to_categories (products_id,categories_id) VALUES ('$productitemid','$id')"); mysql_query("INSERT INTO categories (categories_id) VALUES ('$id')"); mysql_query("INSERT INTO categories_description (categories_id,categories_name) VALUES ('$id','$name')"); mysql_query("INSERT INTO categories_description (categories_name) VALUES ('$name')"); //echo "$categories\n&lt;br /&gt;&lt;br /&gt;"; // or die(mysql_error()); echo "inserted into mysql&lt;br /&gt;&lt;br /&gt;"; //show updated records printf ("Records inserted: %d\n", mysql_affected_rows()); } //close connection mysql_close($con2); ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    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