Calculate percentage ratio from sum amount in mysql database in php -
i have total_amount ($total_amount_column) total sum of amount column down there.
in database, have multiple entry called name , have amount associated them.
so looks in table called "envelope_sub"
name |amount |percentage house |1550.00 | electricity |400.00 | internet |50.00 |
what need calculate automatically percentage column based on total amount sum column. in other words, need percentage ratio each entry , insert them automatically in respective percentage field in database. how can achieve please.
here's how did it
<?php $query = "select * stats user_id='".$nameid."' $where order week desc"; $result = mysql_query($query) or die(mysql_error()); $worked_week = mysql_num_rows($result); if(mysql_num_rows($result)) { $k = 1; while ($row_stats = mysql_fetch_array($result)) { // total section // $total_worked_hours=$total_worked_hours+$row_stats['worked_hours']; $total_sales=$total_sales+$row_stats['sales']; $total_sales=number_format($total_sales,2,'.',''); $total_facials=$total_facials+$row_stats['facials']; $total_double_facials=$total_double_facials+$row_stats['double_facials']; $total_classes=$total_classes+$row_stats['classes']; $total_faces_viewed=$total_faces_viewed+$row_stats['faces_viewed']; $total_interviews=$total_interviews+$row_stats['interviews']; $total_recruits=$total_recruits+$row_stats['recruits']; /// $k++; } // percentage section // $perc_worked_hours = $total_worked_hours / $worked_week; $perc_sales = $total_sales / $worked_week; $perc_facials = $total_facials / $worked_week; $perc_double_facials = $total_double_facials / $worked_week; $perc_classes = $total_classes / $worked_week; $perc_faces_viewed = $total_faces_viewed / $worked_week; $perc_interviews = $total_interviews / $worked_week; $perc_recruits = $total_recruits / $worked_week; // round $perc_worked_hours=number_format($perc_worked_hours,0,'.',''); $perc_sales=number_format($perc_sales,2,'.',''); $perc_facials=number_format($perc_facials,0,'.',''); $perc_double_facials=number_format($perc_double_facials,0,'.',''); $perc_classes=number_format($perc_classes,0,'.',''); $perc_faces_viewed=number_format($perc_faces_viewed,0,'.',''); $perc_interviews=number_format($perc_interviews,0,'.',''); $perc_recruits=number_format($perc_recruits,0,'.',''); // end
Comments
Post a Comment