S
S
samorez7772018-05-27 15:44:52
PHP
samorez777, 2018-05-27 15:44:52

How to get percentage in a loop?

Two tables:
1)product:

id  title      paysystem_id   price
1   Nike           1           200
2  Adidas          2           200
3  Reebok          3          200

2) pay:
id   pay_id      sum     dat
1        1       400   2018-05-26
2        1       400   2018-05-26
3        2       600   2018-05-26

I make a query to the database
$products= \R::getAll("SELECT * FROM product JOIN pay ON product.paysystem_id = pay.pay_id");
my loop outputs just the number and sum fields:
<?php foreach ($products as $product): ?>
<?=$product['sum'];?>
<?php endforeach; ?> The
question is how to calculate the percentage for each id from the product table, from the amount in the pay table.
Example for Nike
1) from table pay->sum id1 = 400+400=800
2) from table product->price id1 = 200/100%=2
3) 800/2= 400%
How to get 400% of the sum in a loop ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
samorez777, 2018-05-27
@samorez777

How to arrange it?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question