0

I've a MySQL server and I'm running a WebShop on it. Is it possible to calculate the sum of all articles on an order. Now when I add a new row I have to call a method in my PHP Script to calculate the sum. Is this possible to automate in MySQL (ex. Procedures)?

With Best Regards Kevin Horvat

llanato
  • 2,508
  • 6
  • 37
  • 59
Kevin Horvat
  • 25
  • 1
  • 1
  • 8

1 Answers1

0
$query="SELECT SUM(tbl_articles.price) as sum FROM ztbl_articles_orders INNER JOIN tbl_articles ON ztbl_articles_orders.articleID = tbl_articles.articleID INNER JOIN tbl_orders ON ztbl_articles_orders.orderID = tbl_orders.orderID WHERE tbl_orders.userID = 3;";
$result= mysqli_query($connection,$query);
$row=mysqli_fetch_array($result,MYSQLI_BOTH);
$sum=$row['sum'];

"$sum" gets the value you want, now you can insert or update with this value.

habib ul haq
  • 824
  • 6
  • 13