Advertisement
Guest User

Untitled

a guest
Feb 27th, 2018
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.47 KB | None | 0 0
  1. <?php
  2. $servername = "localhost";
  3. $username = "11229431_cbsklep";
  4. $password = "v,v@LGokE:5j";
  5. $dbname = "11229431_cbsklep";
  6. $conn = new mysqli($servername, $username, $password, $dbname);
  7.  
  8. if ($conn->connect_error) {
  9.     die("Connection failed: " . $conn->connect_error);
  10. }
  11. $conn -> query("SET NAMES 'utf8'");
  12.  
  13. $sql = "SELECT id_image FROM ps_image_lang WHERE legend = 'Zdjecie'";
  14. $result = $conn->query($sql);
  15.  
  16. $images_id = array();
  17.  
  18. if ($result->num_rows > 0) {
  19.     while($row = $result->fetch_assoc()) {
  20.         $images_id[] = $row['id_image'];
  21.     }
  22. }
  23.  
  24. $ids = join("','",$images_id);
  25.  
  26. $sql = "SELECT id_image, id_product FROM ps_image WHERE id_image IN ('$ids')";
  27. $result = $conn->query($sql);
  28.  
  29. $out = array();
  30.  
  31. if ($result->num_rows > 0) {
  32.     while($row = $result->fetch_assoc()) {
  33.         $out[] = $row;
  34.     }
  35. }
  36.  
  37. $save = array();
  38.  
  39. foreach( $out as $single ) {
  40.     $pid = $single['id_product'];
  41.     $imid = $single['id_image'];
  42.     $sql = "SELECT name FROM ps_product_lang WHERE id_product = $pid";
  43.     $result = $conn->query($sql);
  44.     if ($result->num_rows > 0) {
  45.         while($row = $result->fetch_assoc()) {
  46.             $name = $row['name'];
  47.             $save[] = array( 'id_image' => $imid, 'name' => $name );
  48.         }
  49.     }
  50. }
  51.  
  52.  
  53. foreach( $save as $image ) {
  54.     $id_image = $image['id_image'];
  55.     $name = mysql_real_escape_string($image['name']);
  56.  
  57.     echo $id_image." - ".$name."<br/>";
  58.  
  59.     $sql = "UPDATE ps_image_lang SET legend = '$name' WHERE id_image = $id_image";
  60.     $result = $conn->query($sql);
  61. }
  62.  
  63. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement