You are here:  » Differant XML Hierarchy


Differant XML Hierarchy

Submitted by Bay_Oz on Tue, 2008-06-10 09:56 in

Hi,

im working on a new xml hierarchy.

For instance:

-------------------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<INDEXGRUP>
  <KATEGORI KOD="IDX1012" TANIM="Güvenlik">
    <GRUP KOD="1250" TANIM="CCTV Kamera">
      <URUN KOD="IC-202W-G1" AD="GKB IP CAMERA - IC SERIES(yellow)" MARKA="GKB" GLOBALKOD="IC-202W-G1" SIRKETKOD="IDX">
        <VERGI>KDV18</VERGI>
        <RESIM>http://www.indexpazar.com/all_images/IC-202W-G1.jpg</RESIM>
        <OZELLIK>
          <OZL TANIM="Network Arabirimi" DEGER="Ethernet 10BaseT/100BaseTX" />
          <OZL TANIM="Görüntü Algılayıcı" DEGER="RGB/VGA 1/5&quot; CMOS" />
          <OZL TANIM="Işık Hassasiyeti" DEGER="1 Lux" />
          <OZL TANIM="Lens" DEGER="3,2 mm Sabit" />
          <OZL TANIM="Görüntü Sıkıştırma" DEGER="MPEG-4" />
          <OZL TANIM="Çözünürlük" DEGER="Maksimum 640 x 480" />
          <OZL TANIM="Görüntü Hızı" DEGER="25 fps /PAL,30 fps /NTSC" />
          <OZL TANIM="Bant Genişliği" DEGER="64 K - 2M Bits/Sec" />
          <OZL TANIM="Ses" DEGER="Dahili Mikrofon" />
          <OZL TANIM="Güvenlik" DEGER="Şifre Korumalı" />
          <OZL TANIM="Yönetim Yazılımı" DEGER="Ücretsiz" />
          <OZL TANIM="Kayıt Yazılımı" DEGER="Ücretsiz" />
          <OZL TANIM="İşletim Sistemi" DEGER="Windows XP ve Üzeri" />
          <OZL TANIM="Güç Kaynağı" DEGER="DC 5 V, 1 A" />
          <OZL TANIM="Hareket Algılama" DEGER="Var" />
          <OZL TANIM="e-mail Uyarı" DEGER="Var" />
          <OZL TANIM="Ölçüler" DEGER="125mm x 75mm x 35mm" />
          <OZL TANIM="Ağırlık" DEGER="260 Gr" />
          <OZL TANIM="Garanti Süresi" DEGER="2 Yıl" />
          <OZL TANIM="Kullanıcı Sayısı Unicast" DEGER="4 (Aynı Anda)" />
          <OZL TANIM="Kullanıcı SayısıMulticast" DEGER="Sınırsız" />
          <OZL TANIM="DHCP Desteği" DEGER="Var" />
          <OZL TANIM="Operating Temperature" DEGER="-10 ° C ~ +60 ° C" />
        </OZELLIK>
      </URUN>
      <URUN KOD="IC-202W-G2" AD="GKB IP CAMERA - IC SERIES (black)" MARKA="GKB" GLOBALKOD="IC-202W-G2" SIRKETKOD="IDX">
        <VERGI>KDV18</VERGI>
        <RESIM>http://www.indexpazar.com/all_images/IC-202W-G2.jpg</RESIM>
        <OZELLIK>
          <OZL TANIM="Network Arabirimi" DEGER="Ethernet 10BaseT/100BaseTX" />
          <OZL TANIM="Görüntü Algılayıcı" DEGER="RGB/VGA 1/5&quot; CMOS" />
          <OZL TANIM="Işık Hassasiyeti" DEGER="1 Lux" />
          <OZL TANIM="Lens" DEGER="3,2 mm Sabit" />
          <OZL TANIM="Görüntü Sıkıştırma" DEGER="MPEG-4" />
          <OZL TANIM="Çözünürlük" DEGER="Maksimum 640 x 480" />
          <OZL TANIM="Görüntü Hızı" DEGER="25 fps /PAL,30 fps /NTSC" />
          <OZL TANIM="Bant Genişliği" DEGER="64 K - 2M Bits/Sec" />
          <OZL TANIM="Ses" DEGER="Dahili Mikrofon" />
          <OZL TANIM="Güvenlik" DEGER="Şifre Korumalı" />
          <OZL TANIM="Yönetim Yazılımı" DEGER="Ücretsiz" />
          <OZL TANIM="Kayıt Yazılımı" DEGER="Ücretsiz" />
          <OZL TANIM="İşletim Sistemi" DEGER="Windows XP ve Üzeri" />
          <OZL TANIM="Güç Kaynağı" DEGER="DC 5 V, 1 A" />
          <OZL TANIM="Hareket Algılama" DEGER="Var" />
          <OZL TANIM="e-mail Uyarı" DEGER="Var" />
          <OZL TANIM="Çalışma Sıcaklığı" DEGER="-10ºC - +60ºC" />
          <OZL TANIM="Ölçüler" DEGER="125mm x 75mm x 35mm" />
          <OZL TANIM="Ağırlık" DEGER="260 Gr" />
          <OZL TANIM="Garanti Süresi" DEGER="2 Yıl" />
          <OZL TANIM="Kullanıcı Sayısı Unicast" DEGER="4 (Aynı Anda)" />
          <OZL TANIM="Kullanıcı SayısıMulticast" DEGER="Sınırsız" />
          <OZL TANIM="DHCP Desteği" DEGER="Var" />
        </OZELLIK>
      </URUN>
    </GRUP>
  </KATEGORI>

KATEGORI = Category in english KOD = Code , TANIM = Description
GRUP = Group in english
URUN = Product

Source : http://www.pdtedarik.com/entegrasyon/xml/katalog.xml

All products of same categories are in just one category label.( like that.)

Therefor MagicParser can read just first record,i need all records importing to mysql.

Have you any solutions about that?

Best Regards,
S. Ozgur CANKURT

Submitted by support on Tue, 2008-06-10 11:00

Hello,

With this style of XML, you will find that Magic Parser does not auto-detect the best format string fro accessing all the information. This is because there are lots of OZL fields, so this is the element that is detected.

Looking at your XML, it looks like you need to use the following format string:

xml|INDEXGRUP/KATEGORI/GRUP/URUN/

Click here to see your XML being parsed using this format string.

If you then use the "Generate PHP Source", you will see how to use this format string in your call to MagicParser_parse().

Hope this helps!
Cheers,
David.

Submitted by Bay_Oz on Tue, 2008-06-10 12:10

Thank you David for quickly response.But i have problem with this style.

xml|INDEXGRUP/KATEGORI/GRUP/URUN/

this style dont includes , tag and values.Yes i can read all products details with your style but i need some modification for category information.

i need to import this data to my mysql db.

can you suggest anyway for this category problem?

  <KATEGORI KOD="IDX1012" TANIM="Güvenlik"> | <CATEGORY CODE="IDX1012" DESCRIPTION="Security">
    <GRUP KOD="1250" TANIM="CCTV Kamera"> | <GROUP CODE="1250" DESCRIPTION="CCTV Camera">

Submitted by support on Tue, 2008-06-10 12:35

Hi,

Because the information you want is not described by element names, you best way to handle this is to loop through $record, and construct an array of categories ($ozellik) by looking for "TANIM" and "DEGER" within each item in $record.

Once you have constructed the array, you can then insert values from the new $ozellik into MySQL as normal. Here is an example to show you what I mean:

<?php
  header
("Content-Type: text/plain;charset=utf-8");
  require(
"MagicParser.php");
  function 
myRecordHandler($record)
  {
    
$ozellik = array();
    foreach(
$record as $k => $v)
    {
      if (
strpos($k,"TANIM"))
      {
        
$tanim $v;
      }
      if (
strpos($k,"DEGER"))
      {
        
$deger $v;
      }
      if (
$tanim && $deger)
      {
        
$ozellik[$tanim] = $deger;
        
$tanim "";
        
$deger "";
      }
    }
    
print_r($ozellik);
  }  
  
$url "http://www.pdtedarik.com/entegrasyon/xml/katalog.xml";
  
MagicParser_parse($url,"myRecordHandler","xml|INDEXGRUP/KATEGORI/GRUP/URUN/");
?>

Here is the output running on this server (first record only)

At the point where you see this code:

   print_r($ozellik);

This is where you could insert the values into MySQL, for example the network interface value would be in the array variable:

   $ozellik["Network Arabirimi"]

And of course, you can use other variables from the main $record array, such as:

  $record["URUN-KOD"]

So, your code to insert into MySQL might look like this (but with more fields!)

  $sql = "INSERT INTO product SET
            kod='".mysql_escape_string($record["URUN-KOD"])."',
            network_interface='".mysql_escape_string($ozellik["Network Arabirimi"])."'
            ";
  mysql_query($sql);

Always use mysql_escape_string() when constructing SQL from variables so that the content does not break the structure of the SQL.

Hope this helps!
Cheers,
David.

Submitted by Bay_Oz on Tue, 2008-06-10 13:48

David i realize now my previous message is missing.

i want to said that i need a solution for category and group tags.

<KATEGORI KOD="IDX1012" TANIM="Güvenlik">
<GRUP KOD="1250" TANIM="CCTV Kamera">

my source:

<CATEGORY CODE="IDV1012" DESCRIPTION="Security">
<GROUP CODE="1250" DESCRIPTION="CCTV Camera">
$product_data1
$product_data2
$product_data3
</GROUP>
</CATEGORY>

All products of same categories are in just one category label.

When i import xml to mysql, i need a filter:

$sql = "INSERT INTO veri (CATEGORYCODE, PRODUCT_NAME, PRODUCT_PRICE, PRODUCT_IMAGE) VALUES (
'".mysql_real_escape_string($record["CATEGORY-CODE"])."',
'".mysql_real_escape_string($record["PRODUCT_NAME"])."',
'".mysql_real_escape_string($record["PRODUCT_PRICE"])."',
'".mysql_real_escape_string($record["PRODUCT_IMAGE"])."')WHERE CATEGORY.CODE = "IDX1012" ";
mysql_query($sql);

i should filter all data with CATEGORY and GROUP variable.How can i define category and group variable?

Please pay attention this status :

<CATEGORY CODE="IDV1012" DESCRIPTION="Security">
<GROUP CODE="1250" DESCRIPTION="CCTV Camera">
$product_data1($record["URUN-KOD"] etc...)
$product_data2
$product_data3
</GROUP>
</CATEGORY>

Submitted by support on Tue, 2008-06-10 14:24

Hello,

Ah - I see what you want to get now. Unfortunately, this is quite complicated as Magic Parser is not designed to be a full-hierarchical parser; it is designed to make it easy to access lots of records at the same level.

However, it cam be done; but what you need to do is first parse your file at the higher level of INDEXGRUP/KATEGORI/ and build up an array to map products (by code) to category and group code.

So, the first part is to build up an array of kods $kods, like this:

<?php
  header
("Content-Type: text/plain;charset=utf-8");
  require(
"MagicParser.php");
  
$kods = array();
  function 
myRecordHandler($record)
  {
    global 
$kods;
    foreach(
$record as $k => $v)
    {
      if ((
strpos($k,"GRUP/URUN")!==FALSE) && (strpos($k,"KOD")!==FALSE))
      {
        
$kods[$v]["kategori_kod"] = $kategori_kod;
        
$kods[$v]["grup_kod"] = $grup_kod;
      }
      elseif ((
strpos($k,"GRUP")!==FALSE) && (strpos($k,"KOD")!==FALSE))
      {
        
$grup_kod $v;
      }
      elseif ((
strpos($k,"KATEGORI")!==FALSE) && (strpos($k,"KOD")!==FALSE))
      {
        
$kategori_kod $v;
      }
    }
  }
  
$url "http://www.pdtedarik.com/entegrasyon/xml/katalog.xml";
  
MagicParser_parse($url,"myRecordHandler","xml|INDEXGRUP/KATEGORI/");
  
print_r($kods);
?>

Click here to see the output of this script.

Now what you need to do is combine this code with the first script, so you can see the category code and group code for each product, like this:

<?php
  header
("Content-Type: text/plain;charset=utf-8");
  require(
"MagicParser.php");
  
$kods = array();
  function 
myKategoriRecordHandler($record)
  {
    global 
$kods;
    foreach(
$record as $k => $v)
    {
      if ((
strpos($k,"GRUP/URUN")!==FALSE) && (strpos($k,"KOD")!==FALSE))
      {
        
$kods[$v]["kategori_kod"] = $kategori_kod;
        
$kods[$v]["grup_kod"] = $grup_kod;
      }
      elseif ((
strpos($k,"GRUP")!==FALSE) && (strpos($k,"KOD")!==FALSE))
      {
        
$grup_kod $v;
      }
      elseif ((
strpos($k,"KATEGORI")!==FALSE) && (strpos($k,"KOD")!==FALSE))
      {
        
$kategori_kod $v;
      }
    }
  }
  function 
myUrunRecordHandler($record)
  {
    global 
$kods;
    
$ozellik = array();
    foreach(
$record as $k => $v)
    {
      if (
strpos($k,"TANIM"))
      {
        
$tanim $v;
      }
      if (
strpos($k,"DEGER"))
      {
        
$deger $v;
      }
      if (
$tanim && $deger)
      {
        
$ozellik[$tanim] = $deger;
        
$tanim "";
        
$deger "";
      }
    }
    
// this code to see what is in $ozellik
    
print_r($ozellik);
    
// this code to see what is in $record
    
print_r($record);
    
// this code to see what is in $kods for this urun
    
print_r($kods[$record["URUN-KOD"]]);
    
// now you can use all those variables to make your SQL for this urun
  
}  
  
$url "http://www.pdtedarik.com/entegrasyon/xml/katalog.xml";
  
MagicParser_parse($url,"myKategoriRecordHandler","xml|INDEXGRUP/KATEGORI/");
  
MagicParser_parse($url,"myUrunRecordHandler","xml|INDEXGRUP/KATEGORI/GRUP/URUN/");
?>

I'm sorry this is not ideal, but if you want to use Magic Parser for this sort of XML this is the only way to do it. Don't forget, if you decide you cannot use Magic Parser for this you can of course have your money back.

Hope this helps!

Cheers,
David.

Submitted by Bay_Oz on Wed, 2008-06-11 13:44

Hi David,

i trying to use this code

$sql2 = "INSERT INTO `pdtedarik_db`.`cscart_products_categories` (
`product_id` ,
`category_id` ,
`link_type` ,
`position`
)
VALUES (
'".mysql_real_escape_string($record["URUN-KOD"])."', '".mysql_real_escape_string($kod[$record["URUN-KOD"]])."', 'M', '0')";

$kategori = $kod[$record["URUN-KOD"]]
$product_code = $record["URUN-KOD"])

+------------+--------------+-------------+------------------------+
| product_id | category_id | link_type |position
+------------+--------------+-------------+------------------------+
| 1 | $kategori | M(default) | 0(default)
| 2 | $kategori | M | 0
| 3 | $kategori | M | 0
| 4 | $kategori | M | 0
+------------+--------------+-------------+------------------------+

i can add data from xml to my products table.but my products table has a product_id field and it has auto_increment feature.
when i add this products category information from xml to products_category table i should use this id value.
How can i do?

and can you give me a filter code?(like just show <KATEGORI KOD="IDX1012" products?

$kategori = $kod[$record["URUN-KOD"]]
select products from xml where $kategorui ="IDX1012";

i hope its clear.

Best Regards and Thank you for all
S. Ozgur CANKURT

Submitted by support on Wed, 2008-06-11 13:54

Hi,

Because you have actual product IDs (the URON-KODs), I would carry on using these instead of the auto-increment ID value.

This would mean that you don't necessarily have to update your products_category table whenever you update the products table, for example.

For your filter; instead of using the $kategorui, you should specify the field name, for example:

  $sql = "SELECT * FROM products WHERE kategorui = '".mysql_real_escape_string($kod[$record["URUN-KOD"]])."'";
  $result = mysql_query($sql);
  while($row = mysql_fetch_assoc($result))
  {
    print_r($row);
  }

Hope this helps!
Cheers,
David.

Submitted by Bay_Oz on Wed, 2008-06-11 14:07

Hi
i guess i could not explain.

please show this result : http://www.pdtedarik.com/entegrasyon/xml/test.php

you can see all categories and products data.

but i want to see just products in a category,i need a filter with kategori_kod and group_kod variables.
(kategori_kod] => IDX1012 [grup_kod] => 1250)

Thanks,

test.php source:

<?php
  require("MagicParser.php");
  require_once('baglanti.php');
  $kods = array();
  function myKategoriRecordHandler($record)
  {
    global $kods;
    foreach($record as $k => $v)
    {
      if ((strpos($k,"GRUP/URUN")!==FALSE) && (strpos($k,"KOD")!==FALSE))
      {
        $kods[$v]["kategori_kod"] = $kategori_kod;
        $kods[$v]["grup_kod"] = $grup_kod;
      }
      elseif ((strpos($k,"GRUP")!==FALSE) && (strpos($k,"KOD")!==FALSE))
      {
        $grup_kod = $v;
      }
      elseif ((strpos($k,"KATEGORI")!==FALSE) && (strpos($k,"KOD")!==FALSE))
      {
        $kategori_kod = $v;
      }
    }
  }
  function myUrunRecordHandler($record)
  {
    global $kods;
    $ozellik = array();
    foreach($record as $k => $v)
    {
      if (strpos($k,"TANIM"))
      {
        $tanim = $v;
      }
      if (strpos($k,"DEGER"))
      {
        $deger = $v;
      }
      if ($tanim && $deger)
      {
        $ozellik[$tanim] = $deger;
        $tanim = "";
        $deger = "";
      }
    }
      print_r($kods[$record["URUN-KOD"]]);
    // this code to see what is in $ozellik
      //print_r($ozellik);
    // this code to see what is in $record
         print_r($record);
    // this code to see what is in $kods for this urun
    // now you can use all those variables to make your SQL for this urun
  }
  $url = "katalog.xml";
  MagicParser_parse($url,"myKategoriRecordHandler","xml|INDEXGRUP/KATEGORI/");
  MagicParser_parse($url,"myUrunRecordHandler","xml|INDEXGRUP/KATEGORI/GRUP/URUN/");
?>

Submitted by support on Wed, 2008-06-11 14:16

Hello,

I think I understand now.

You can filter it by "return"ing from myUrunRecordHandler if the product is not in the category and group that you want, using this code:

if (
   ($kods[$record["URUN-KOD"]]["kategori_kod"] <> "IDX1012")
   ||
   ($kods[$record["URUN-KOD"]]["grup_kod"] <> "1250")
   )
   return;

...here it is in your test.php:

<?php
  
require("MagicParser.php");
  require_once(
'baglanti.php');
  
$kods = array();
  function 
myKategoriRecordHandler($record)
  {
    global 
$kods;
    foreach(
$record as $k => $v)
    {
      if ((
strpos($k,"GRUP/URUN")!==FALSE) && (strpos($k,"KOD")!==FALSE))
      {
        
$kods[$v]["kategori_kod"] = $kategori_kod;
        
$kods[$v]["grup_kod"] = $grup_kod;
      }
      elseif ((
strpos($k,"GRUP")!==FALSE) && (strpos($k,"KOD")!==FALSE))
      {
        
$grup_kod $v;
      }
      elseif ((
strpos($k,"KATEGORI")!==FALSE) && (strpos($k,"KOD")!==FALSE))
      {
        
$kategori_kod $v;
      }
    }
  }
  function 
myUrunRecordHandler($record)
  {
    global 
$kods;
    
$ozellik = array();
    foreach(
$record as $k => $v)
    {
      if (
strpos($k,"TANIM"))
      {
        
$tanim $v;
      }
      if (
strpos($k,"DEGER"))
      {
        
$deger $v;
      }
      if (
$tanim && $deger)
      {
        
$ozellik[$tanim] = $deger;
        
$tanim "";
        
$deger "";
      }
    }
    if (
       (
$kods[$record["URUN-KOD"]]["kategori_kod"] <> "IDX1012")
       ||
       (
$kods[$record["URUN-KOD"]]["grup_kod"] <> "1250")
       )
       return;
    
print_r($kods[$record["URUN-KOD"]]);
    
// this code to see what is in $ozellik
    //print_r($ozellik);
    // this code to see what is in $record
    
print_r($record);
    
// this code to see what is in $kods for this urun
    // now you can use all those variables to make your SQL for this urun
  
}
  
$url "katalog.xml";
  
MagicParser_parse($url,"myKategoriRecordHandler","xml|INDEXGRUP/KATEGORI/");
  
MagicParser_parse($url,"myUrunRecordHandler","xml|INDEXGRUP/KATEGORI/GRUP/URUN/");
?>

Hope this helps!
Cheers,
David.

Submitted by Bay_Oz on Thu, 2008-06-12 14:15

Hi David,
Thank you for all help.i need a last help.i have a headache for that. :)

you already now my xml structure.

i need importing my data with this database style.

for products table
+------------+--------------+
| product_id | product_code
+------------+--------------+
| 1 | $productcode
| 2 | $productcode
| 3 | $productcode
| 4 | $productcode
+------------+--------------+
product_id = auto_increment
$productcode = from xml

for products_categories table
+------------+--------------+-------------+------------------------+
| product_id | category_id | link_type |position
+------------+--------------+-------------+------------------------+
| 1 | $kategori | M | 0
| 2 | $kategori | M | 0
| 3 | $kategori | M | 0
| 4 | $kategori | M | 0
+------------+--------------+-------------+------------------------+
product_id = from products table in db
$category_id = "93" (i can give this value)
"M" and "0" default value

for product_descriptions table
+------------+--------------+
| product_id | product |
+------------+--------------+
| 1 | $productname |
| 2 | $productname |
| 3 | $productname |
| 4 | $productname |
+------------+--------------+
product_id = from products table in db
$productname = record["URUN-AD"])from xml file WHERE product_descriptions.product_id = products.product_id and products.product_code = record["URUN-KOD"])

<URUN KOD="IC-202W-G1" AD="GKB IP CAMERA - IC SERIES(yellow)" MARKA="GKB" GLOBALKOD="IC-202W-G1" SIRKETKOD="IDX">

IC-202W-G1 || GKB IP CAMERA - IC SERIES(yellow)

and i create this file with your help but its not completed.

<?php
  
require("MagicParser.php");
  require_once(
'baglanti.php');
  
$kods = array();
  function 
myKategoriRecordHandler($record)
  {
    global 
$kods;
    foreach(
$record as $k => $v)
    {
      if ((
strpos($k,"GRUP/URUN")!==FALSE) && (strpos($k,"KOD")!==FALSE))
      {
        
$kods[$v]["kategori_kod"] = $kategori_kod;
        
$kods[$v]["grup_kod"] = $grup_kod;
        
$kods[$v]["urun_kod"] = $urun_kod;
      }
      elseif ((
strpos($k,"GRUP")!==FALSE) && (strpos($k,"KOD")!==FALSE))
      {
        
$grup_kod $v;
      }
      elseif ((
strpos($k,"KATEGORI")!==FALSE) && (strpos($k,"KOD")!==FALSE))
      {
        
$kategori_kod $v;
      }
      elseif ((
strpos($k,"URUN")!==FALSE) && (strpos($k,"KOD")!==FALSE))
      {
        
$urun_kod $v;
      }
    }
  }
  function 
myUrunRecordHandler($record)
  {
    global 
$kods;
    
$ozellik = array();
    foreach(
$record as $k => $v)
    {
      if (
strpos($k,"TANIM"))
      {
        
$tanim $v;
      }
      if (
strpos($k,"DEGER"))
      {
        
$deger $v;
      }
      if (
$tanim && $deger)
      {
        
$ozellik[$tanim] = $deger;
        
$tanim "";
        
$deger "";
      }
    }
    if (
       (
$kods[$record["URUN-KOD"]]["kategori_kod"] <> "IDX1010")
       ||
       (
$kods[$record["URUN-KOD"]]["grup_kod"] <> "1128")
       )
       return;
    
//print_r($kods[$record["URUN-KOD"]]);
    // this code to see what is in $ozellik
    //print_r($ozellik);
    // this code to see what is in $record
    //print_r($record);
    // this code to see what is in $kods for this urun
    // now you can use all those variables to make your SQL for this urun
    
global $counter;
     global 
$sql;
     
$counter++;
     
$urunkodu $record["URUN-KOD"]; //URUN BİLGİLERİ
     
$urunadi $kods["URUN-AD"];
  
mysql_query("DELETE from products where product_code = '$urunkodu'");// i wrote this for ban the same record again,i can not do bcz primary key is auto_increment,if you can develop more its better.
  
mysql_query("DELETE from product_descriptions ");
  
mysql_query("DELETE from products_categories");
    
$sql "INSERT IGNORE INTO `products` (
`product_id` ,
`product_code` ,
`product_type` ,
`owner_id` ,
`avail` ,
`manufacturer_id` ,
`list_price` ,
`amount` ,
`min_amount` ,
`weight` ,
`length` ,
`width` ,
`height` ,
`shipping_freight` ,
`low_avail_limit` ,
`timestamp` ,
`is_edp` ,
`edp_shipping` ,
`tracking` ,
`free_shipping` ,
`feature_comparison` ,
`zero_price_action` ,
`is_pbp` ,
`is_op` ,
`is_oper` ,
`supplier_id` ,
`is_returnable` ,
`return_period` ,
`desi`
)
VALUES (
 '','"
.mysql_real_escape_string($urunkodu)."', 'N', '0', 'Y', '0', '0.00', '0', '0', '0.00', '0', '0', '0', '0.00', '0', '0', 'N', 'N', 'B', 'N', 'N', 'R', 'N', 'N', 'N', '0', 'Y', '10', NULL
)"
;
$sql2 "INSERT  INTO `products_categories` (
`product_id`
)
SELECT products.product_id FROM products"
;
$aciklamalar1 "INSERT INTO `products` (
`product_id`
)
SELECT products.product_id FROM products"
;
$aciklamalar2 "UPDATE`products`SET lang_code ='TR', product='$urunadi'";
mysql_query($aciklamalar1);
mysql_query($aciklamalar2);
if (!
mysql_query($sql2))
{
// SQL failed, print error message and abort
print mysql_error();exit();
}
if (!
mysql_query($sql))
{
// SQL failed, print error message and abort
print mysql_error();exit();
}
mysql_query("UPDATE products_categories SET category_id = '93'");    
  }
  
$url "katalog.xml";
  
MagicParser_parse($url,"myKategoriRecordHandler","xml|INDEXGRUP/KATEGORI/");
  
MagicParser_parse($url,"myUrunRecordHandler","xml|INDEXGRUP/KATEGORI/GRUP/URUN/");
  print 
" ".$counter." adet kayıt eklendi.";
print 
"Son Kayıt: ".$sql."";
?>

Thank you for everythings.

Best Regards,
S. Ozgur CANKURT

Submitted by support on Thu, 2008-06-12 15:24

Hi,

The first problem I think I can see - you have this code:

  mysql_query("DELETE from product_descriptions ");
  mysql_query("DELETE from products_categories");

As this stands, it will delete every record in product_descriptions and products_categories
- is this what you want to do?

...but to make these only delete the current product, you need product_id from your products table.

However, since product_code is also unique, have you thought about making product_code the primary
key, then you don't need to get product_id for the current product? Then, these queries would be:

  mysql_query("DELETE from product_descriptions WHERE product_code='$urunkodu'");
  mysql_query("DELETE from products_categories WHERE product_code='$urunkodu'");

Does that make sense?

Cheers,
David.

Submitted by Bay_Oz on Fri, 2008-06-13 05:44

Hi David,
i understand your suggestion its right but i dont have product_code in product_categories and product_descriptions tables.
maybe it can be that:

mysql_query("DELETE from product_descriptions WHERE product_descriptions.product_id = products.product_id");
mysql_query("DELETE from product_categories WHERE product_categories.product_id = products.product_id");
mysql_query("DELETE from products");

But my real problem about inserting products,categories and descriptions data from xml.

<KATEGORI KOD="IDX1012" TANIM="Güvenlik"> // KOD should be use for categories table
<URUN KOD="IC-202W-G1" AD="GKB IP CAMERA - IC SERIES(yellow)" MARKA="GKB" GLOBALKOD="IC-202W-G1" SIRKETKOD="IDX">
//KOD should be use for products table
// AD should be use for product_descriptions table
<OZELLIK>
          <OZL TANIM="Network Arabirimi" DEGER="Ethernet 10BaseT/100BaseTX" />
          <OZL TANIM="Görüntü Algılayıcı" DEGER="RGB/VGA 1/5&quot; CMOS" />
          <OZL TANIM="Işık Hassasiyeti" DEGER="1 Lux" />
          <OZL TANIM="Lens" DEGER="3,2 mm Sabit" />
          <OZL TANIM="Görüntü Sıkıştırma" DEGER="MPEG-4" />
          <OZL TANIM="Çözünürlük" DEGER="Maksimum 640 x 480" />
          <OZL TANIM="Görüntü Hızı" DEGER="25 fps /PAL,30 fps /NTSC" />
          <OZL TANIM="Bant Genişliği" DEGER="64 K - 2M Bits/Sec" />
          <OZL TANIM="Ses" DEGER="Dahili Mikrofon" />
          <OZL TANIM="Güvenlik" DEGER="Şifre Korumalı" />
          <OZL TANIM="Yönetim Yazılımı" DEGER="Ücretsiz" />
          <OZL TANIM="Kayıt Yazılımı" DEGER="Ücretsiz" />
          <OZL TANIM="İşletim Sistemi" DEGER="Windows XP ve Üzeri" />
          <OZL TANIM="Güç Kaynağı" DEGER="DC 5 V, 1 A" />
          <OZL TANIM="Hareket Algılama" DEGER="Var" />
          <OZL TANIM="e-mail Uyarı" DEGER="Var" />
          <OZL TANIM="Ölçüler" DEGER="125mm x 75mm x 35mm" />
          <OZL TANIM="Ağırlık" DEGER="260 Gr" />
          <OZL TANIM="Garanti Süresi" DEGER="2 Yıl" />
          <OZL TANIM="Kullanıcı Sayısı Unicast" DEGER="4 (Aynı Anda)" />
          <OZL TANIM="Kullanıcı SayısıMulticast" DEGER="Sınırsız" />
          <OZL TANIM="DHCP Desteği" DEGER="Var" />
          <OZL TANIM="Operating Temperature" DEGER="-10 ° C ~ +60 ° C" />
        </OZELLIK>
//All data in /OZELLIK should be use in products_descriptions
like
Network Arabirimi = Ethernet 10BaseT/100BaseTX

Best Regards,
S. Ozgur CANKURT

Submitted by Bay_Oz on Fri, 2008-06-13 09:40

Hi David,
i try to use that.

$urunadi = $record["URUN-AD"] <> $record["URUN-KOD"]; //productname of this code
mysql_query("UPDATE cscart_product_descriptions p SET p.product = '$urunadi' where p.product_code=$urunkodu");

but its turn all records "1" why?

Submitted by support on Fri, 2008-06-13 09:46

Hi,

It is making them all 1 because of this line:

$urunadi = $record["URUN-AD"] <> $record["URUN-KOD"];

The <> is a comparison operator, so it returns TRUE (1) or FALSE (0).

I think it should just be:

$urunadi = $record["URUN-AD"];

Cheers,
David.

Submitted by Bay_Oz on Fri, 2008-06-13 09:52

Hi
$urunadi = $record["URUN-AD"];

i use already this code,but i guess i have mistake when i update my table.

mysql_query("UPDATE cscart_product_descriptions p SET p.product = '$urunadi'");

Because it writes all records just last xml records.

my records :

INSERT INTO `cscart_product_descriptions` VALUES(31581, 'CC247B', 'TR', 'HP Photosmart A826 Home Foto Center', '', '', '', '', '', '', '');
INSERT INTO `cscart_product_descriptions` VALUES(31582, 'CC975B', 'TR', 'HP Photosmart A826 Home Foto Center', '', '', '', '', '', '', '');
INSERT INTO `cscart_product_descriptions` VALUES(31583, 'Q5736A', 'TR', 'HP Photosmart A826 Home Foto Center', '', '', '', '', '', '', '');
INSERT INTO `cscart_product_descriptions` VALUES(31584, 'Q5747B', 'TR', 'HP Photosmart A826 Home Foto Center', '', '', '', '', '', '', '');
INSERT INTO `cscart_product_descriptions` VALUES(31585, 'Q7058B', 'TR', 'HP Photosmart A826 Home Foto Center', '', '', '', '', '', '', '');
INSERT INTO `cscart_product_descriptions` VALUES(31586, 'Q7115A', 'TR', 'HP Photosmart A826 Home Foto Center', '', '', '', '', '', '', '');
INSERT INTO `cscart_product_descriptions` VALUES(31587, 'Q8361B', 'TR', 'HP Photosmart A826 Home Foto Center', '', '', '', '', '', '', '');
INSERT INTO `cscart_product_descriptions` VALUES(31588, 'Q8492B', 'TR', 'HP Photosmart A826 Home Foto Center', '', '', '', '', '', '', '');
INSERT INTO `cscart_product_descriptions` VALUES(31589, 'Q8517A', 'TR', 'HP Photosmart A826 Home Foto Center', '', '', '', '', '', '', '');
INSERT INTO `cscart_product_descriptions` VALUES(31590, 'Q8531A', 'TR', 'HP Photosmart A826 Home Foto Center', '', '', '', '', '', '', '');
INSERT INTO `cscart_product_descriptions` VALUES(31591, 'Q8541A', 'TR', 'HP Photosmart A826 Home Foto Center', '', '', '', '', '', '', '');

how can i fix that?

Submitted by Bay_Oz on Fri, 2008-06-13 10:57

Hi,
i use that but i can not fix my problem.i guess its about my mysql query.

$urunadi = $record["URUN-AD"];

$aciklama = "INSERTINTO cscart_product_descriptions(product_code )
VALUES('".mysql_real_escape_string($urunkodu)."')";

it writes just last records data from xml.it should insert all data from xml.

Thanks,

Submitted by support on Fri, 2008-06-13 11:08

Hi,

Is the primary key (id) field on your table set to auto-increment?

Submitted by Bay_Oz on Fri, 2008-06-13 11:24

No primarykey is not auto_increment.

CREATE TABLE `product_descriptions` (
  `product_id` int(11) unsigned NOT NULL default '0',
  `product_code` varchar(32) NOT NULL default '',
  `lang_code` char(2) NOT NULL default 'TR',
  `product` varchar(255) NOT NULL default '',
  `shortname` varchar(255) NOT NULL default '',
  `short_description` text NOT NULL,
  `full_description` text NOT NULL,
  `meta_keywords` varchar(255) NOT NULL default '',
  `meta_description` varchar(255) NOT NULL default '',
  `search_words` text NOT NULL,
  `page_title` varchar(255) NOT NULL default '',
  PRIMARY KEY (`product_code`),
  FULLTEXT KEY `pr` (`product`),
  FULLTEXT KEY `shrt` (`short_description`),
  FULLTEXT KEY `full` (`full_description`),
  FULLTEXT KEY `pr_shrt` (`product`,`short_description`),
  FULLTEXT KEY `pr_full` (`product`,`full_description`),
  FULLTEXT KEY `shrt_full` (`short_description`,`full_description`),
  FULLTEXT KEY `pr_shrt_full` (`product`,`short_description`,`full_description`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

i use this sql query for inserting data.

$aciklama = "INSERT INTO product_descriptions(
product_code )
SELECT product_code FROM products";
<code>
<code>
mysql_query("UPDATE product_descriptions pp,products p SET pp.product_id = p.product_id where pp.product_code = p.product_code");
<code>
and its my result.
<code>
INSERT INTO `product_descriptions` VALUES(31928, 'Q8550A', 'TR', '', '', '', '', '', '', '', '');

i need to fill product field in product_descriptions table with $record["URUN-AD"].

Thanks

Submitted by Bay_Oz on Fri, 2008-06-13 11:36

NO its not auto_increment.

$aciklama = "INSERT INTO product_descriptions(
product_code,product )
VALUES('".mysql_real_escape_string($urunkodu)."','".mysql_real_escape_string($urunadi)."')";

i use that but it insert just on records. WHY?i want all records from xml.

Submitted by Bay_Oz on Fri, 2008-06-13 12:09

finally i fixed this problem thanks. :)

Submitted by Bay_Oz on Fri, 2008-06-13 12:31

and
you created a code for me.

$ozellik = array();
    foreach($record as $k => $v)
    {
      if (strpos($k,"TANIM"))
      {
        $tanim = $v;
      }
      if (strpos($k,"DEGER"))
      {
        $deger = $v;
      }
      if ($tanim && $deger)
      {
        $ozellik[$tanim] = $deger;
        $tanim = "";
        $deger = "";
      }
    }

i can use this codes with this style :

$urunaciklamasi = $ozellik["Web Adresi"];
INSERT '".mysql_real_escape_string($urunadi)."' like...

but i need a solution for /OZL label.i want to insert all data in /OZL label

for instance:

 <OZL TANIM="Baskı Boyutu" DEGER="10 x 15 cm ve 13 x 18 cm" />
          <OZL TANIM="Baskı Teknolojisi" DEGER="HP Thermal Mürekkep Püskürtmeli" />
          <OZL TANIM="Kartuj Sayısı" DEGER="1" />
          <OZL TANIM="Siyah Baskı Hızı (PPM)" DEGER="39 ppm" />
          <OZL TANIM="Renkli Baskı Hızı (PPM)" DEGER="39 ppm" />
          <OZL TANIM="Baskı Çözünürlük Renkli (DPI)" DEGER="4800 dpi x 1200 dpi" />
          <OZL TANIM="Bellek (STD/MAX)" DEGER="64 MB" />
          <OZL TANIM="Kağıt Kapasitesi (STD/ MAX)" DEGER="20 syf. / 20 syf." />
          <OZL TANIM="Çift Taraflı Baskı Özelliği" DEGER="Yok" />
          <OZL TANIM="Cd-Dvd Baskı Özelliği" DEGER="Var" />
          <OZL TANIM="Yazıcı Dilleri" DEGER="HP PCL 3 GUI, PML" />
          <OZL TANIM="Standart Arabirim" DEGER="USB, USB 2.0 özellikleriyle uyumlu, PictBridge, bellek kartı yuvaları" />
          <OZL TANIM="Opsiyonel Arabirim" DEGER="Yok" />
          <OZL TANIM="Desteklediği İşletim Sistemleri" DEGER="Windows® 98 SE, 2000, Me, XPH, XPP, XPP x64 Edition;Mac OS X v10.3.9 ve üstü" />
          <OZL TANIM="Garanti (AY)" DEGER="12 Ay Sınırlı Donanım Garantisi" />
          <OZL TANIM="Özel Açıklama" DEGER="Bilgisayar kullanmadan 6.1 ekran üzerinden fotoğraflarınızı basar." />
          <OZL TANIM="Web Adresi" DEGER="www.hp.com.tr" />

i want to insert data to mysql like that:

  Baskı Teknolojisi = HP Thermal Mürekkep Püskürtmeli
  Kartuj Sayısı = 1
  Siyah Baskı Hızı (PPM)= 39 ppm

What is necessary solution for that,can i use your $ozellik function?

Thank you for all,

Best Regards,
S. Ozgur CANKURT

Submitted by support on Fri, 2008-06-13 12:44

Hello,

The way I would do this; because I don't think you always know what the fields are is to have a separate table:

Table: ozl

product_kod | tanim | deger

...and then yes, you can use the same code; and you can have a loop to insert the data:

  mysql_query("DELETE FROM ozl WHERE product_kod = '".mysql_real_escape_string($record["URUN-KOD"])."'");
  foreach($ozellik as $tanim => $deger)
  {
    mysql_query("INSERT INTO ozl (product_kod,tanim,deger) VALUES ('".mysql_real_escape_string($record["URON-KOD"])."','".mysql_real_escape_string($tanim)."','".mysql_real_escape_string($deger)."')";
  }

Hope this helps!
Cheers,
David.

Submitted by Bay_Oz on Fri, 2008-06-13 13:25

Hi David,
Thank you for loop codes.but it insert just first $ozellik record

$aciklama = "INSERT INTO cscart_product_descriptions(
product_code,product,full_description)
VALUES('".mysql_real_escape_string($urunkodu)."','".mysql_real_escape_string($urunadi)."','".mysql_real_escape_string($tanim)." = ".mysql_real_escape_string($deger)."')";
    mysql_query($aciklama);

Baskı Boyutu = 10 cm x 15 cm

it works just first $ozellik Baskı Boyutu and $deger.But if i use echo $tanim; i can see all $ozellik data i guess i have a mistake when i importing?

what do you think about that?

Thank you for all.
Best Regards,
S. Ozgur CANKURT

Submitted by support on Fri, 2008-06-13 13:58

Hi,

Can you post the part of your code importing in the loop, I will have a look...

Cheers,
David.

Submitted by Bay_Oz on Sat, 2008-06-14 08:25

Hi David,

 foreach($ozellik as $tanim => $deger)
  {
    $aciklama = "INSERT INTO product_descriptions(
product_code,product,full_description)
VALUES('".mysql_real_escape_string($urunkodu)."','".mysql_real_escape_string($urunadi)."','".mysql_real_escape_string($tanim)." = ".mysql_real_escape_string($deger)."')";
    mysql_query($aciklama); }

i use this.

Best Regards,
S. Ozgur CANKURT

Submitted by Bay_Oz on Sat, 2008-06-14 10:12

Hi David,

Loop code is that :

mysql_query("DELETE FROM ozl WHERE product_kod = '".mysql_real_escape_string($record["URUN-KOD"])."'");
  foreach($ozellik as $tanim => $deger)
  {
    mysql_query("INSERT INTO ozl (product_kod,tanim,deger) VALUES ('".mysql_real_escape_string($record["URON-KOD"])."','".mysql_real_escape_string($tanim)."','".mysql_real_escape_string($deger)."')";
  }

Submitted by support on Sat, 2008-06-14 10:16

Hi,

Do you mean after it has run, you only have 1 record (per product) in the ozl table?

Submitted by Bay_Oz on Mon, 2008-06-16 08:12

Hi David,
i use that.

foreach($ozellik as $tanim => $deger)
  {
   $tanim2= mb_convert_encoding($tanim, "ISO-8859-9" , "UTF-8");
$deger2= mb_convert_encoding($deger, "ISO-8859-9" , "UTF-8");
   $aciklama = "INSERT INTO product_descriptions(
product_code,product,full_description)
VALUES('".mysql_real_escape_string($urunkodu)."','".mysql_real_escape_string($urunadi)."','".mysql_real_escape_string($tanim2)." = ".mysql_real_escape_string($deger2)."')";
    mysql_query($aciklama);
}

and result :

+------------+--------------+------------------+
| product_id | product_code | full_description |
+------------+--------------+------------------+
| 1 | $code | Baský Boyutu = A4 - A3
| 2 | $code | Baský Boyutu = A4 - A3
| 3 | $code | Baský Boyutu = 10 cm x 15 cm
| 4 | $code | Baský Boyutu = 10 x 15 cm ve 13 x 18 cm
+------------+--------------+-------------+----+

Baskı Boyutu is my first record in ozellik from xml.

<OZELLIK>
          <OZL TANIM="Baskı Boyutu" DEGER="A4" />
          <OZL TANIM="Baskı Teknolojisi" DEGER="HP Thermal Mürekkep Püskürtmeli" />
          <OZL TANIM="Kartuj Sayısı" DEGER="6" />
          <OZL TANIM="Siyah Baskı Hızı (PPM)" DEGER="34 ppm" />
          <OZL TANIM="Renkli Baskı Hızı (PPM)" DEGER="33 ppm" />
          <OZL TANIM="Baskı Çözünürlük SB (DPI)" DEGER="1200 dpi x 1200 dpi" />
          <OZL TANIM="Baskı Çözünürlük Renkli (DPI)" DEGER="4800 dpi x 1200 dpi" />
          <OZL TANIM="Baskı Kapasitesi (AYLIK)" DEGER="3000 syf." />
          <OZL TANIM="Bellek (STD/MAX)" DEGER="64 MB" />
          <OZL TANIM="Kağıt Kapasitesi (STD/ MAX)" DEGER="100 syf. / 100 sfy." />
          <OZL TANIM="Çift Taraflı Baskı Özelliği" DEGER="Otomatik (isteğe bağlı)" />
          <OZL TANIM="Cd-Dvd Baskı Özelliği" DEGER="Yok" />
          <OZL TANIM="Yazıcı Dilleri" DEGER="HP PCL 3" />
          <OZL TANIM="Standart Arabirim" DEGER="USB - USB 2.0 özellikleriyle uyumludur, PictBridge, Ethernet, bellek kartı yuvaları, HP bt500 Bluetooth Kablosuz Yazıcı ve PC Adaptoru" />
          <OZL TANIM="Opsiyonel Arabirim" DEGER="Yok" />
          <OZL TANIM="Desteklediği İşletim Sistemleri" DEGER="Windows® 2000 (SP3), Windows® XP Home, Windows® XP Professional, Windows Vista™ İçin Hazır; Mac OS X v10.3.9;Mac OS X v10.4" />
          <OZL TANIM="Garanti (AY)" DEGER="12 Ay Sınırlı Donanım Garantisi" />
          <OZL TANIM="Özel Açıklama" DEGER="8,6 cm ekranlı yenilenen dokunmatik ekran." />
          <OZL TANIM="Web Adresi" DEGER="www.hp.com.tr" />
        </OZELLIK>

  <OZL TANIM="Baskı Boyutu" DEGER="A4" />

i want insert all data in /OZELLIK label from xml to my db.

Best Regards,
S. Ozgur CANKURT

Submitted by Bay_Oz on Mon, 2008-06-16 13:33

Hi David,

have you any solution about this problem?

Thanks,

Submitted by support on Mon, 2008-06-16 13:59

Hi,

Could you perhaps post the entire function so I can see more of the code?

I am a bit confused with the field names etc.!

Thanks,
David.

Submitted by Bay_Oz on Mon, 2008-06-16 14:08

Hi David,

im sending you my all codes.

Hi David,

im sending you my all codes.

<?php
  require("MagicParser.php");
  require_once('baglanti.php');
  $kods = array();
  mysql_query("DELETE FROM product_images");
  mysql_query("DELETE FROM product_images_links");
  function myKategoriRecordHandler($record)
  {
    global $kods;
    foreach($record as $k => $v)
    {
      if ((strpos($k,"GRUP/URUN")!==FALSE) && (strpos($k,"KOD")!==FALSE))
      {
        $kods[$v]["kategori_kod"] = $kategori_kod;
        $kods[$v]["grup_kod"] = $grup_kod;
      }
      elseif ((strpos($k,"GRUP")!==FALSE) && (strpos($k,"KOD")!==FALSE))
      {
        $grup_kod = $v;
      }
      elseif ((strpos($k,"KATEGORI")!==FALSE) && (strpos($k,"KOD")!==FALSE))
      {
        $kategori_kod = $v;
}
    }
  }
  function myUrunRecordHandler($record)
  {
    global $kods;
    $ozellik = array();
    foreach($record as $k => $v)
    {
      if (strpos($k,"TANIM"))
      {
        $tanim = $v;
      }
      if (strpos($k,"DEGER"))
      {
        $deger = $v;
      }
      if ($tanim && $deger)
      {
        $ozellik[$tanim] = $deger;
        $tanim = "";
        $deger = "";
      }
    }
    if (
       ($kods[$record["URUN-KOD"]]["kategori_kod"] <> "IDX1010")
       ||
       ($kods[$record["URUN-KOD"]]["grup_kod"] <> "1128")
)
       return;
global $counter;
     $counter++;
     $urunkodu = $record["URUN-KOD"];
$urunadiutf8 = $record["URUN-AD"];
$urunadi= mb_convert_encoding($urunadiutf8, "ISO-8859-9" , "UTF-8");
$urunresmi = $record["RESIM"];
  mysql_query("DELETE from products where product_code = '$urunkodu'");
  mysql_query("DELETE from product_descriptions where product_code = '$urunkodu'");
  mysql_query("DELETE from products_categories");
   mysql_query("delete from seo_names where object_id = (select product_id from products)");
  //sıfırlamalar
$sql = "INSERT INTO products (`product_id` ,`product_code` ,`product_type` ,`owner_id` ,`avail` ,`manufacturer_id` ,
`list_price` ,
`amount` ,
`min_amount` ,
`weight` ,
`length` ,
`width` ,
`height` ,
`shipping_freight` ,
`low_avail_limit` ,
`timestamp` ,
`is_edp` ,
`edp_shipping` ,
`tracking` ,
`free_shipping` ,
`feature_comparison` ,
`zero_price_action` ,
`is_pbp` ,
`is_op` ,
`is_oper` ,
`supplier_id` ,
`is_returnable` ,
`return_period` ,
`desi`
)
VALUES (
 '','".mysql_real_escape_string($urunkodu)."', 'N', '0', 'Y', '0', '0.00', '0', '0', '0.00', '0', '0', '0', '0.00', '0', '0', 'N', 'N', 'B', 'N', 'N', 'R', 'N', 'N', 'N', '0', 'Y', '10', NULL
)";
$sql2 = "INSERT INTO `pdtedarik_db`.`products_categories` (
`product_id`
)
SELECT product_id FROM products";
$resimler = "INSERT INTO product_images(
image_path,image_x,image_y,product_code )
VALUES('".mysql_real_escape_string($urunresmi)."','250','210','".mysql_real_escape_string($urunkodu)."')";
mysql_query($resimler);
  foreach($ozellik as $tanim => $deger)
  {
   $tanim2= mb_convert_encoding($tanim, "ISO-8859-9" , "UTF-8");
$deger2= mb_convert_encoding($deger, "ISO-8859-9" , "UTF-8");
   $aciklama = "INSERT INTO product_descriptions(
product_code,product,full_description)
VALUES('".mysql_real_escape_string($urunkodu)."','".mysql_real_escape_string($urunadi)."','".mysql_real_escape_string($tanim2)." = ".mysql_real_escape_string($deger2)."')";
    mysql_query($aciklama);
}
if (!mysql_query($sql))
{
print mysql_error();exit();
}
if (!mysql_query($sql2))
{
print mysql_error();exit();
}
  }
  $url = "katalog.xml";
  MagicParser_parse($url,"myKategoriRecordHandler","xml|INDEXGRUP/KATEGORI/");
  MagicParser_parse($url,"myUrunRecordHandler","xml|INDEXGRUP/KATEGORI/GRUP/URUN/");
  print " ".$counter." adet kayıt eklendi.";
 mysql_query("UPDATE product_descriptions pp,products p SET pp.product_id = p.product_id where pp.product_code = p.product_code");
mysql_query("UPDATE products_categories SET category_id = '93'");
mysql_query("INSERT INTO product_images_links(
product_id)
SELECT product_id FROM products");
mysql_query("UPDATE product_images p ,products pp SET p.product_code = pp.product_code where p.image_id = pp.image_id");
mysql_query("UPDATE product_images_links p ,products pp ,product_images t SET p.image_path = SUBSTR(t.image_path,-10,6)
 where p.product_id = pp.product_id and pp.product_code = t.product_code");
mysql_query("UPDATE product_images_links p ,products pp ,product_images t SET p.image_id = t.image_id where p.product_id = pp.product_id and pp.product_code = t.product_code");
?>

i fixed many problem with your help.im at last now.you already know problem,i want to insert all /OZL fields.

Thanks,

Submitted by support on Mon, 2008-06-16 14:14

Hi,

At first glance, your code looks fine.

So I am wondering, in your product_descriptions table, is product_code a Primary Key?

If so, it must be unique so only the first description will be inserted. This could cause it.

If that is what is wrong, you need to make another primary key field (id) using auto-increment,
and the product_code can still be indexed, but a normal index, NOT a unique index...!

Cheers,
David.

Submitted by Bay_Oz on Tue, 2008-06-17 06:24

Hi David,

its my product_description table.What should i do?

CREATE TABLE `product_descriptions` (
  `product_id` int(11) unsigned NOT NULL default '0',
  `product_code` varchar(32) NOT NULL default '',
  `lang_code` char(2) NOT NULL default 'TR',
  `product` varchar(255) NOT NULL default '',
  `shortname` varchar(255) NOT NULL default '',
  `short_description` text NOT NULL,
  `full_description` text NOT NULL,
  `meta_keywords` varchar(255) NOT NULL default '',
  `meta_description` varchar(255) NOT NULL default '',
  `search_words` text NOT NULL,
  `page_title` varchar(255) NOT NULL default '',
  PRIMARY KEY (`product_id`,`product_code`),
  FULLTEXT KEY `pr` (`product`),
  FULLTEXT KEY `shrt` (`short_description`),
  FULLTEXT KEY `full` (`full_description`),
  FULLTEXT KEY `pr_shrt` (`product`,`short_description`),
  FULLTEXT KEY `pr_full` (`product`,`full_description`),
  FULLTEXT KEY `shrt_full` (`short_description`,`full_description`),
  FULLTEXT KEY `pr_shrt_full` (`product`,`short_description`,`full_description`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

Thanks for all.
S. Ozgur CANKURT

Submitted by support on Wed, 2008-06-18 08:46

Hi,

Looking at your code; I think it looks like you only want 1 product_descriptions record
per product, so the table definition can stay as it is.

But then this needs to change:

  foreach($ozellik as $tanim => $deger)
  {
   $tanim2= mb_convert_encoding($tanim, "ISO-8859-9" , "UTF-8");
$deger2= mb_convert_encoding($deger, "ISO-8859-9" , "UTF-8");
   $aciklama = "INSERT INTO product_descriptions(
product_code,product,full_description) VALUES('".mysql_real_escape_string($urunkodu)."','".mysql_real_escape_string($urunadi)."','".mysql_real_escape_string($tanim2)." = ".mysql_real_escape_string($deger2)."')";
    mysql_query($aciklama);
  }

Do you want to build up a long description from each of the TANIM = DEGER?

If so, you can do that like this instead:

  $full_description = "";
  foreach($ozellik as $tanim => $deger)
  {
    $tanim2= mb_convert_encoding($tanim, "ISO-8859-9" , "UTF-8");
    $deger2= mb_convert_encoding($deger, "ISO-8859-9" , "UTF-8");
    $full_description .= $tanim2 . " = " . $deger2 . " ";
  }
  $aciklama = "INSERT INTO product_descriptions(product_code,product,full_description) VALUES('".mysql_real_escape_string($urunkodu)."','".mysql_real_escape_string($urunadi)."','".mysql_real_escape_string($full_description)."')";
  mysql_query($aciklama);

Hope this helps,
Cheers,
David.

Submitted by Bay_Oz on Mon, 2008-06-30 15:15

Hi David,
your code works perfectly.Thank you for all you are best.

i have a little problem for you i can not fix.i want to write all $sql variable to a txt file.(gorevler.sql)

function myUrunRecordHandler($record)
  {
      global $kods;
$ozellik = array();
       $urunkodu = $record["URUN-KOD"];
$sql = "INSERT INTO cscart_products(`product_id` ,`product_code` ,`product_type` ,`owner_id` ,`avail` ,`manufacturer_id` ,`list_price` ,`amount` ,`min_amount` ,`weight` ,`length`,`width` ,`height` ,`shipping_freight` ,`low_avail_limit` ,`timestamp` ,`is_edp` ,`edp_shipping` ,`tracking` ,`free_shipping` ,`feature_comparison` ,`zero_price_action` ,`is_pbp` ,is_op ,`is_oper` ,`supplier_id` ,`is_returnable` ,`return_period` ,`desi`) VALUES ( '','".mysql_real_escape_string($urunkodu)."', 'N', '0', 'Y', '0', '0.00', '0', '0', '0.00', '0', '0', '0', '0.00', '0', '', 'N', 'N', 'B', 'N', 'N', 'R', 'N', 'N', 'N', '0', 'Y', '10', '700')";
 fwrite($dosya,$sql);
 $sql .= "\n";
 }
 fclose($dosya);

it write just one record and after add a "\n" but i need all sql data.

it mean

VALUES ( '','".mysql_real_escape_string($urunkodu)."', 'N', '0', 'Y', '0', '0.00', '0', '0', '0.00', '0', '0', '0', '0.00', '0', '', 'N', 'N', 'B', 'N', 'N', 'R', 'N', 'N', 'N', '0', 'Y', '10', '700')";

'".mysql_real_escape_string($urunkodu)."' = its a variable from xml.(you already know my system)

i want to write

"INSERT INTO cscart_products(`product_id` ,`product_code` ,`product_type` ,`owner_id` ,`avail` ,`manufacturer_id` ,`list_price` ,`amount` ,`min_amount` ,`weight` ,`length`,`width` ,`height` ,`shipping_freight` ,`low_avail_limit` ,`timestamp` ,`is_edp` ,`edp_shipping` ,`tracking` ,`free_shipping` ,`feature_comparison` ,`zero_price_action` ,`is_pbp` ,is_op ,`is_oper` ,`supplier_id` ,`is_returnable` ,`return_period` ,`desi`) VALUES ( '','1111111111111111', 'N', '0', 'Y', '0', '0.00', '0', '0', '0.00', '0', '0', '0', '0.00', '0', '', 'N', 'N', 'B', 'N', 'N', 'R', 'N', 'N', 'N', '0', 'Y', '10', '700')"
INSERT INTO cscart_products(`product_id` ,`product_code` ,`product_type` ,`owner_id` ,`avail` ,`manufacturer_id` ,`list_price` ,`amount` ,`min_amount` ,`weight` ,`length`,`width` ,`height` ,`shipping_freight` ,`low_avail_limit` ,`timestamp` ,`is_edp` ,`edp_shipping` ,`tracking` ,`free_shipping` ,`feature_comparison` ,`zero_price_action` ,`is_pbp` ,is_op ,`is_oper` ,`supplier_id` ,`is_returnable` ,`return_period` ,`desi`) VALUES ( '','2222222222222222222', 'N', '0', 'Y', '0', '0.00', '0', '0', '0.00', '0', '0', '0', '0.00', '0', '', 'N', 'N', 'B', 'N', 'N', 'R', 'N', 'N', 'N', '0', 'Y', '10', '700')"
like that.

Submitted by Bay_Oz on Tue, 2008-07-01 13:24

Thanks david,
i find a solution for my previous problem.(it was about fwrite func)

but i need really your help now about magicparser.

<?php
set_time_limit(0);
  require("./inc/MagicParser.php");
  $kods = array();
  function myKategoriRecordHandler($record)
  {
    global $kods;
    foreach($record as $k => $v)
    {
      if ((strpos($k,"GRUP/URUN")!==FALSE) && (strpos($k,"KOD")!==FALSE))
      {
        $kods[$v]["kategori_kod"] = $kategori_kod;
        $kods[$v]["grup_kod"] = $grup_kod;
      }
      elseif ((strpos($k,"GRUP")!==FALSE) && (strpos($k,"KOD")!==FALSE))
      {
        $grup_kod = $v;
      }
      elseif ((strpos($k,"KATEGORI")!==FALSE) && (strpos($k,"KOD")!==FALSE))
      {
        $kategori_kod = $v;
}
  }
  }
  function myUrunRecordHandler($record)
  {
  global $kods;
    $ozellik = array();
foreach($record as $k => $v)
    {
      if (strpos($k,"TANIM"))
      {
        $tanim = $v;
      }
      if (strpos($k,"DEGER"))
      {
        $deger = $v;
      }
      if ($tanim && $deger)
      {
        $ozellik[$tanim] = $deger;
        $tanim = "";
        $deger = "";
    }
}
$urunkodu = $record["URUN-KOD"];
//kategori değerini yazdıran kod.
    $kategori = $kods[$record["URUN-KOD"]]["kategori_kod"];
    $grup = $kods[$record["URUN-KOD"]]["grup_kod"];
$urunadiutf8 = $record["URUN-AD"];
$urunadi= mb_convert_encoding($urunadiutf8, "ISO-8859-9" , "UTF-8");
$urunresmi = $record["RESIM"];
     $resimisim = substr($urunresmi, 37);
$full_description = "";
  foreach($ozellik as $tanim => $deger)
  {
    $tanim2= mb_convert_encoding($tanim, "ISO-8859-9" , "UTF-8");
    $deger2= mb_convert_encoding($deger, "ISO-8859-9" , "UTF-8");
    $full_description .= "<li>" .$tanim2 . " = " . $deger2 . "</li>";
  }
  $aciklama = "INSERT INTO product_descriptions(product_code,product,full_description,kategori_kod,grup_kod) VALUES('$urunkodu','$urunadi','<ul>$full_description</ul>','$kategori','$grup')";
$aciklama .= "\n";
  $aciklamadosyasi = "urun_aciklamasi.sql";
$aciklamadata=fopen($aciklamadosyasi, "a");
fwrite($aciklamadata,$aciklama);
fclose($aciklamadata);
  }
  $url = "katalog.xml";
  MagicParser_parse($url,"myKategoriRecordHandler","xml|INDEXGRUP/KATEGORI/");
  MagicParser_parse($url,"myUrunRecordHandler","xml|INDEXGRUP/KATEGORI/GRUP/URUN/");
?>

i have this codes.i want to use '$kategori','$grup' variables for all products records.But you already know my xml structure its not standart.you created this function for me but its not work.

function myKategoriRecordHandler($record)
  {
    global $kods;
    foreach($record as $k => $v)
    {
      if ((strpos($k,"GRUP/URUN")!==FALSE) && (strpos($k,"KOD")!==FALSE))
      {
        $kods[$v]["kategori_kod"] = $kategori_kod;
        $kods[$v]["grup_kod"] = $grup_kod;
      }
      elseif ((strpos($k,"GRUP")!==FALSE) && (strpos($k,"KOD")!==FALSE))
      {
        $grup_kod = $v;
      }
      elseif ((strpos($k,"KATEGORI")!==FALSE) && (strpos($k,"KOD")!==FALSE))
      {
        $kategori_kod = $v;
}
  }
  }

how can i fix that?

Best Regards,
S. Ozgur CANKURT

Submitted by support on Tue, 2008-07-08 08:49

Hi,

Apologies for the delay.

Could you describe a little more what is not working....

Are you just getting no values in the $kods array?

Thanks,
David.

Submitted by Bay_Oz on Fri, 2008-07-11 10:27

Hi David,

im fixed all problems with your great help.But i should create a better algorithm for categories because it needs more time for parsing.

 function myKategoriRecordHandler($record)
  {
    global $kods;
    foreach($record as $k => $v)
    {
      if ((strpos($k,"GRUP/URUN")!==FALSE) && (strpos($k,"KOD")!==FALSE))
      {
        $kods[$v]["kategori_kod"] = $kategori_kod;
        $kods[$v]["grup_kod"] = $grup_kod;
      }
      elseif ((strpos($k,"GRUP")!==FALSE) && (strpos($k,"KOD")!==FALSE))
      {
        $grup_kod = $v;
      }
      elseif ((strpos($k,"KATEGORI")!==FALSE) && (strpos($k,"KOD")!==FALSE))
      {
        $kategori_kod = $v;
}
 }
  }
$kayitsayisi = 0;
  function myUrunRecordHandler($record)
  {
  $urunkodu = $record["URUN-KOD"];
  $kayitsayisi++;
  global $kods;
    $ozellik = array();
foreach($record as $k => $v)
    {
      if (strpos($k,"TANIM"))
      {
        $tanim = $v;
      }
      if (strpos($k,"DEGER"))
      {
        $deger = $v;
      }
      if ($tanim && $deger)
      {
        $ozellik[$tanim] = $deger;
        $tanim = "";
        $deger = "";
    }
}
  $kategori = $kods[$record["URUN-KOD"]]["kategori_kod"];
         $grup = $kods[$record["URUN-KOD"]]["grup_kod"];
//category works
$urunadiutf8 = $record["URUN-AD"];
$urunadi= mb_convert_encoding($urunadiutf8, "ISO-8859-9" , "UTF-8");
$full_description = "";
  foreach($ozellik as $tanim => $deger)
  {
  $duzenleme = array(
"'" => ' ',
);
    $tanim2= mb_convert_encoding($tanim, "ISO-8859-9" , "UTF-8");
    $deger2= mb_convert_encoding($deger, "ISO-8859-9" , "UTF-8");
$tanim3 = strtr($tanim2,$duzenleme);
$deger3 = strtr($deger2,$duzenleme);
    $full_description .= "<li>" .$tanim3 . " = " . $deger3 . "</li>";
  }
    $duzenleme = array(
"'" => ' ',
);
  $urunadi2 = strtr($urunadi,$duzenleme);
  $aciklama = "INSERT INTO product_descriptions(product_code,product,full_description,kategori_kod,grup_kod) VALUES('$urunkodu','$urunadi2','<ul>$full_description</ul>','$kategori','$grup');";
mysql_query($aciklama);
}

What should i do for faster process time? (my xml file 3mb but this process time 35 min.+)

i need a better way for function myKategoriRecordHandler($record).


function myKategoriRecordHandler($record){
}
function myUrunRecordHandler($record){
$kategori = $kods[$record["URUN-KOD"]]["kategori_kod"];
$grup = $kods[$record["URUN-KOD"]]["grup_kod"];
}

Best Regards,
S. Ozgur CANKURT

Submitted by Bay_Oz on Tue, 2008-07-15 10:22

Hi David,
im waiting your solution about this problem.

Thanks,
S. Ozgur CANKURT

Submitted by support on Tue, 2008-07-15 10:36

hi,

Would it be possible for you to put the XML on a web site so that I can download it and study this for you and see if it can be speeded up?

Please reply to your registration code or forum registration email with a link and i'll download the feed and then see what the best way to process it would be...

Alternatively, if it will .zip reasonably small you could email the feed to me directly but a link would be best...

Cheers,
David.

Submitted by Bay_Oz on Tue, 2008-07-15 13:50

I sent you sample XML data on support@iaaisoftware.com

Thanks