product_to_category
product_id  category_id parent_id
1          500          0
1          554          500
1          630          554
category
category_id category_name       parent_id
500          Pets           0
554          Pet Supplies       500
630          Pet Healthcare     554
700          Groceries          0
760          Bake Supplies      700
830          Toppings           760
Above is the format for category and the category path for a product , what i wanted is that
product_id 1 changed the category from 630 to 760 (Pet Healthcare to Toppings) means that the parent id would also need to change , but i have totally no idea how should i do it for all parent_id
Below is my code that i managed to do ( but only able to update the last product_to_category) , but did not update the parent_id for other line
$this->writedb->query("UPDATE product_to_category SET parent_id = '" . $getparentcategory . "' WHERE product_id =  '" . $getallproduct['product_id'] . "' AND category_id = '" . (int)$category_id . "' ");
Original :
Pets > Pet Supplies > Pet Healthcare
If edit "Pet Healthcare" to Toppings i want it to update to :
Groceries > Bake Supplies > Toppings
In easier explaination is that when updating the last category ,it will also update the parent id to the latest one . ( for example if edit "Pet Healthcare" to "Topping" , "Pets > Pet Supplies" will also update to " Groceries > Back Supplies "
The problem right now is from "product_to_category" , which need to remove/update it to correct category and parent_id
 
     
     
    