<?php
require_once ("varables.php");

    $connect = @mysqli_connect($hostname,$username,$password,$database);
    if($connect)
    {
        @mysqli_query($connect,"SET CHARACTER SET utf8;");

			$query = "SELECT * FROM ".$tbl_category1;
			$catres = @mysqli_query($connect,$query);
			if($catres){
			 while($row = @mysqli_fetch_assoc($catres)){
         $cats = $row["m_local_id"].$row["s_local_id"];
         	$query = "SELECT * FROM ".$tbl_products." WHERE P_id LIKE '".$cats."%'";
    			$pres = @mysqli_query($connect,$query);
          if($pres){
             while($myrow = @mysqli_fetch_assoc($pres)){
                 $cat1id = $row["cat"];
                 $cat2id = $row["id"];
                 $query = "UPDATE ".$tbl_products." SET cat1 = '".$cat1id."', cat2 = '".$cat2id."' WHERE id = '".$myrow["id"]."'";
                 @mysqli_query($connect,$query);
             }
          }
          else{

              echo @mysqli_error($connect);
              return;
          }
       }
			}
      else {
        echo @mysqli_error($connect);
        return;
      }
		}
    echo "همگام سازی با موفقیت انجام شد...!";
?>
