bullex Posted December 12, 2012 Share Posted December 12, 2012 (edited) I need a little help for a script theat makes a import in to a table from 2 xml files . The probles is theat i could do the insert from the first xml file but when i try to import data from the second xml ( the update script) does not work. <?php error_reporting(E_ALL ^ E_NOTICE); ini_set('display_errors', 1); ini_set('max_execution_time', 999999999); require_once('config.php'); require_once('functions.php'); require_once('class.GetProd.php'); $html = file_get_contents('xml/cezar5423.xml'); $GetProd = new GetProd(); $GetProd->parameters = array('TYPE', 'BRAND', 'TITLE', 'VOLUME', 'SEX', 'NOTE', 'SET', 'PICTURE', 'EAN', 'DAMAGED', 'TESTER'); $product = $GetProd->processing($html); foreach ( $product as $product_id => $val ) { $sefurl = sefurl($product[$product_id]['TITLE']); if ( strlen($sefurl) > 0 ) { $type = mysql_real_escape_string(trim($product[$product_id]['TYPE'])); $brand = mysql_real_escape_string(trim($product[$product_id]['BRAND'])); $title = mysql_real_escape_string(trim($product[$product_id]['TITLE'])); $volume = mysql_real_escape_string(trim($product[$product_id]['VOLUME'])); $sex = mysql_real_escape_string(trim($product[$product_id]['SEX'])); $note = mysql_real_escape_string(trim($product[$product_id]['NOTE'])); $set = mysql_real_escape_string(trim($product[$product_id]['SET'])); $ean = mysql_real_escape_string(trim($product[$product_id]['EAN'])); $damaged = mysql_real_escape_string(trim($product[$product_id]['DAMAGED'])); $tester = mysql_real_escape_string(trim($product[$product_id]['TESTER'])); $date = date('Y-m-d H:i:s', time()); if ( mysql_num_rows(mysql_query("SELECT * FROM `products` WHERE id='$product_id'")) < 1 ) { mysql_query("INSERT INTO products (`id`, `sku`, `name`, `producer`, `type`, `volume`, `sex`, `note`, `set`, `damaged`, `tester`, `image`, `sefurl`, `created`) VALUES ('$product_id', '$ean', '$title', '$brand', '$type', '$volume', '$sex', '$note', '$set', '$damaged', '$tester', '$sefurl', '$sefurl', '$date')"); } } } $html = file_get_contents('xml/cezar54233.xml'); $GetProd->parameters = array('PRICE', 'AVAILABILITY', 'STOCK'); $product = $GetProd->processing($html); foreach ( $product as $product_id => $val ) { $stock = $product[$product_id]['STOCK']; $price = $product[$product_id]['PRICE']; $published = ( $product[$product_id]['AVAILABILITY'] == 'in stock' ) ? 1 : 0; mysql_query("UPDATE `products` SET stock='$stock', price='$price', published='$published' WHERE id='$product_id'"); } ?>DONE Edited December 12, 2012 by bullex Quote Link to comment https://forums.phpfreaks.com/topic/271896-import-data-from-xml-file-to-database/ 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.