Forum Moderators: coopster
example:
500.00 should be 5.00
in php, it's coming off as 7.07
code:
$query = "SELECT employee, SUM(balance) FROM commission where `date` < DATE_SUB(CURDATE(), INTERVAL 30 DAY) GROUP BY employee";
$total_sold = $row['SUM(balance)'];
$percentage = ($total_sold / '99');
echo number_format($percentage,2);
what am i doing wrong?
$percentage = ($total_sold*.01);
Hope this helps! :)
employee1 (last month)200 / 2.00
employee1 (this month)700 / 7.00
employee2 (this month)52.5 / 0.53
in the database:
2007-01-09 09:02:46 employee1 = 200.00
2007-02-09 09:02:17 employee1 = 500.00
2007-02-09 09:02:17 employee2 = 52.50
so it was not the math causing my troubles, it was how i was pulling the dates.
what i want to do is display their balances separated by month.
so for employee1 it should be:
employee1 (last month)200 / 2.00
employee1 (this month)700 / 7.00
essentially what i want to do, is showcase their commission balances for this month and last month.
my queries (i'm no php whiz obviously, so i have these running in 2 different queries.):
//this month
$query = "SELECT employee, SUM(balance) FROM commission where `date` < DATE_SUB(CURDATE(), INTERVAL 30 DAY) GROUP BY date"; //last month
$query = "SELECT employee, SUM(balance) FROM commission where `date` > DATE_SUB(CURDATE(), INTERVAL 60 DAY) GROUP BY employee"; thank you for your help, i've been pulling my hair out for about an hour trying to figure out how such simplistic math was fudging up :)
is it logical to have 2 queries like i do now or is there a way to condense them into 1?
fixed queries (does what i want, but is there a way to limit it by MONTH, rather than 30 days?)
//this month
$query = "SELECT employee, SUM(balance) FROM commission where `date` < DATE_SUB(CURDATE(), INTERVAL 30 DAY) GROUP BY date";
//last month
$query = "SELECT employee, SUM(balance) FROM commission where `date` > DATE_SUB(CURDATE(), INTERVAL 30 DAY) GROUP BY employee";
30 DAY maybe something like 1 MONTH would be better. Good luck! :)