Your Location is: Home > Php

PHP - Get total from values in XML

From: Belgrade View: 1861 N.N 

Question

Im trying to make sql update query to update quantity of products.

For example I have the following XML:

<products>
  <product>
     <shop_id>1</shop_id>
     <external_id>1111</external_id>
     <quantity>3</quantity>
  </product>
  <product>
     <shop_id>1</shop_id>
     <external_id>2222</external_id>
     <quantity>1</quantity>
 </product>
 <product>
     <shop_id>2</shop_id>
     <external_id>1111</external_id>
     <quantity>5</quantity>
 </product>
</products>

So, the product "1111" is in two stores - first store [shop_id = 1] quantity is 3, and the second store [shop_id = 2] quantity is 5. So I need to store somehow in array the information, that the product "1111" has quantity of 8 (total from all stores), and the product "2222" has quantity of 1 (total from all stores). After that i will make foreach the final array and then will create sql query.

Best answer