Advertisement
Guest User

Untitled

a guest
Jan 10th, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.77 KB | None | 0 0
  1. <?php
  2.  
  3.     $servername = "d58093.mysql.zone.ee";
  4.     $username = "d58093sa114985";
  5.     $password = "";
  6.     $dbname = "d58093_bredencom";
  7.      
  8.     // Create connection
  9.     $conn = mysqli_connect($servername, $username, $password, $dbname);
  10.  
  11.     // Check connection
  12.     if (!$conn) {
  13.         die("Connection failed: " . mysqli_connect_error());
  14.     }
  15.  
  16.     $xml = simplexml_load_file("https://www.bredenkids.com/erply/suurused.php");
  17.  
  18.     /* näidisarray tootekoodidega */
  19.     $products = ['121965', '121936'];
  20.  
  21.     $sql = "SELECT product_id FROM jk2031_otp_option_value WHERE child_option_value_id IN (76, 75, 81, 123) GROUP BY product_id ORDER BY product_id ASC";
  22.     $result = mysqli_query($conn, $sql);
  23.  
  24.     if (mysqli_num_rows($result) > 0)
  25.     {
  26.         // output data of each row
  27.         while($row = mysqli_fetch_assoc($result))
  28.         {    
  29.             $products[] = $row['product_id'];
  30.         }
  31.     }
  32.     /* käime läbi kõik tooted mis on XMLis */
  33.     foreach ($xml->products->children() as $product)
  34.     {
  35.         if (empty ($products)) exit;
  36.        
  37.         if (in_array($product->product_id, $products))
  38.         {
  39.  
  40.             /* kui kogus on 0 või väiksem siis lähme edasi loopiga */
  41.             if ($product->sizes->size->attributes()->qty <= 0)
  42.             {
  43.                 continue;
  44.             }
  45.             else
  46.             {
  47.                 $product_id = (STRING) $product->sizes->size->attributes()->product_id;
  48.                 $otp_id = (STRING) $product->sizes->size->attributes()->otp_id;
  49.                 $sql = 'INSERT INTO jk2031_product_filter(product_id, filter_id) VALUES("' . $product_id . '", "' . $otp_id .'")';
  50.                 mysqli_query($sql);
  51.             }
  52.         }
  53.     }
  54.     mysqli_close($conn);
  55.  
  56. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement