Skip to content
Advertisement

I want to update the purchases table quantity value from order_item if the order is canceled in php

Please check the below code and please help me the correct syntax to used.

JavaScript

Please find the below table details

JavaScript

expected answer should add the quantities from order_item which match the order_item.purchase_id = purchases.id

Advertisement

Answer

Firstly this seems like redundant data and therefore not something that should really be stored in the database… I’m not sure what you’re using the data for but it seems like you could do something better with SUM()? As that appears to be the intended goal anyway?

Anyway answering the question as asked:

SQL

JavaScript

Additionally you have a variable in your query which should be substituted for a placeholder in a prepared statement as follows:

mysqli

JavaScript

PDO

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement