0
I need to add the amount of each product that was sold by grouping it by "id_product" and adding its quantities. That is, in the example below I have 4 requests that need to print on screen + - as follows:
Total qtd coca cola : 6
Total qtd moda catupiry : 11
Total valor coca cola: 24,00
Total valor moda catupiry: 55,00
The data is saved in a json array in the SQL database.
[{"id_produto":"768","qtd":8,"valor_uni":"5.00","produto":"MODA COM CATUPIRY"}]
[{"id_produto":"750","qtd":2,"valor_uni":"4.00","produto":"COCA-COLA LATA"}]
[{"id_produto":"768","qtd":3,"valor_uni":"5.00","produto":"MODA COM CATUPIRY"}]
[{"id_produto":"750","qtd":4,"valor_uni":"4.00","produto":"COCA-COLA LATA"}]
I tried several ways already a week ago and could not. Could help me?
Your code was good. However, when using my equal comes from the database like this: $json = json_decode('[{"id_product":"768","Qtd":8,"valor_uni":"5.00","product":"MODA COM CATUPIRY"}] [{"id_product":"750","Qtd":2,"valor_uni":"4.00","product":"COCA-COLA LATA"}] [{"id_product":"768","Qtd":3,"valor_uni":"5.00","product":"MODA COM CATUPIRY"}] [{"id_product":"750","Qtd":4,"valor_uni":"4.00","product":"COCA-COLA LATA"}]', true); it gives an error: Warning: Invalid argument supplied for foreach()
– Ds Digital
@Dsdigital your code comes exactly like this? 4 json objects?
– Everton Neri