<?php
ini_set('display_errors','On');
error_reporting('E_ALL');
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "dbname";
//$att_id = '208';
for ($att_id = 1; $att_id <= 500; $att_id++ ) {
$conn = mysqli_connect($servername, $username, $password, $dbname);
if (!$conn) {
    echo "нет соединения";
    die("Connection failed: " . mysqli_connect_error());
}
$sql = "SELECT product_id, attribute_id, language_id, text FROM oc5674_product_attribute WHERE attribute_id = '$att_id'";
$result = mysqli_query($conn, $sql);
            if (mysqli_num_rows($result) > 0) {
              
                while($row = mysqli_fetch_assoc($result)) {
                    /*Ватты*/
                    if ($att_id === 197 || $att_id === 201 || $att_id === 215 || $att_id === 216 ){
                        $row["text"]=explode(" ", $row["text"]);
                        $text=$row["text"][0]/1000;
                        mysqli_query($conn, "UPDATE oc5674_product_attribute SET text='".$text."' WHERE attribute_id='".$row["attribute_id"]."' and product_id='".$row["product_id"]."'");
                    }
                    
                    /*
                    кв.м
                    */
                    if ($att_id === 196) {
                    $row["text"]=explode(" ", $row["text"]);
                    $text=$row["text"][0];
                    mysqli_query($conn, "UPDATE oc5674_product_attribute SET text='".$text."' WHERE attribute_id='".$row["attribute_id"]."' and product_id='".$row["product_id"]."'");
                    }
                    /*
                    см и дБ градуссы
                    */
                    if ($att_id === 208 || $att_id === 207 || $att_id === 210 || $att_id === 237 || $att_id === 220 || $att_id === 217 || $att_id === 188) {
                    $mystring = $row["text"];
                    $findme   = 'см';
                    $pos = strpos($mystring, $findme);
                    if (!$pos === false) {
                        $one = array("х"," см","×");
                        $two = array("x","","x");
                        $text = str_replace($one, $two, $row["text"]);
                        $text = str_replace(" ", "", $text);
                        $text = explode("x",$text);
                        $text = $text[0]*10 .'x'.$text[1]*10 .'x'.$text[2]*10;
                        mysqli_query($conn, "UPDATE oc5674_product_attribute SET text='".$text."' WHERE attribute_id='".$row["attribute_id"]."' and product_id='".$row["product_id"]."'");
                        
                    } else {
                        $text = str_replace(" ", "", $row["text"]);
                        $one = array("х"," мм","×","дБ","°С");
                        $two = array("x","","x",""," °С");
                        $text = str_replace($one, $two, $text);
                        mysqli_query($conn, "UPDATE oc5674_product_attribute SET text='".$text."' WHERE attribute_id='".$row["attribute_id"]."' and product_id='".$row["product_id"]."'");
                        
                        
                    }
                    }
                    
                    /*
                    btu
                    */
                    if ($att_id === 225){
                    $row["text"]=explode(" ", $row["text"]);
                    $text=$row["text"][0];
                    mysqli_query($conn, "UPDATE oc5674_product_attribute SET text='".$text."' WHERE attribute_id='".$row["attribute_id"]."' and product_id='".$row["product_id"]."'");
                    }
                    
                    /*
                    длинна трассы м
                    */
                    
                    if ($att_id === 221){
                    $row["text"]=explode(" ", $row["text"]);
                    $text=$row["text"][0];
                    mysqli_query($conn, "UPDATE oc5674_product_attribute SET text='".$text."' WHERE attribute_id='".$row["attribute_id"]."' and product_id='".$row["product_id"]."'");
                    }
                    
                    /*Инвертор
                    */
                    if ($att_id === 183){
                    $text = str_replace("есть", "Есть", $row["text"]);
                    mysqli_query($conn, "UPDATE oc5674_product_attribute SET text='".$text."' WHERE attribute_id='".$row["attribute_id"]."' and product_id='".$row["product_id"]."'");
                    }                   
                }
            } else {
                echo "0 results";
            }
}
mysqli_close($conn);
?>