Question

I have three category in my store,

1.Bio  2.Art  3.Cine 

I want to move all product from "Bio" category to "Cine" category.

I have tried below query but it movies all product but i want only to move "Bio -->to-->Cine"

<?php
$dbhost = 'localhost'; 
$dbname = 'demo'; 
$dbuser = 'vinod';  
$dbpass = 'vinod'; 
$category_id = '3'; //replace with the category id to which you want to add your products to
$tables_prefix = "oc_";

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die   ('Error Code 1!');
mysql_select_db($dbname);

$query = "select product_id from ".$tables_prefix."product;";
$result = mysql_query($query)or die ('Products query error!');

while($product = mysql_fetch_assoc($result)){
    $insert = "insert into ".$tables_prefix."product_to_category values('".$product['product_id']."', '".$category_id."');";
    $insert_result = mysql_query($insert)or die ('Products insert error!');
}

echo "All Done!";

?>

Was it helpful?

Solution

This query should be enough:

UPDATE product_to_category SET category_id = 3 WHERE category_id = 1

This will set the category_id to 3 (Cine) to all products that have category_id 1 (Bio).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top