Answer the question
In order to leave comments, you need to log in
Progress Bar percentage calculation. how in redbeanphp?
Gentlemen, you need to calculate the percentage for each product, and display it in a loop!
There are tables with products:
1) product
id title paysystem_id price(стоимость)
1 Nike 1 200
2 Adidas 2 200
3 Reebok 3 200
id pay_id sum(оплаченно)
1 1 400
2 1 400
3 2 600
Answer the question
In order to leave comments, you need to log in
Unfortunately, I was unable to decipher your formula. Can you describe it in more detail?
Especially the "*100%" section. What it is? How do you imagine multiplying by 100%?
The general principle of making a request is as follows:
SELECT
`product`.*,
SUM(`pay`.`sum`)/`product`.`price`*100 AS 'percent' -- исправьте эту строку, применив правильную формулу.
FROM
`product`
JOIN `pay` ON `product`.`paysystem_id` = `pay`.`pay_id`
GROUP BY `product`.`id`
<?php foreach ($products as $product): ?>
<?= $product['percent'] ?>
<?php endforeach; ?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question