I do not think I can do it through the Database because i first have to get the sum of each one, then Divide it by the total count.
Any other ideas?
Thanks
// excute SQL query ---------- count ----------------
$sql_counttotal = " select count(POLLID) from Table where $POLLID = POLLID";
$sql_countambiance = " select count(Ambiance) from Table where $POLLID = POLLID";
$sql_countservice = " select count(Service) from Table where $POLLID = POLLID";
$sql_countfood = " select count(FOOD) from Table where $POLLID = POLLID";
$sql_countvalue = " select count(Value) from Table where $POLLID = POLLID";
// excute SQL query ---------- sum ----------------
$sql_sumambiance = " select sum(Ambiance) from Table where $POLLID = POLLID";
$sql_sumservice = " select sum(Service) from Table where $POLLID = POLLID";
$sql_sumfood = " select sum(FOOD) from Table where $POLLID = POLLID";
$sql_sumvalue = " select sum(Value) from Table where $POLLID = POLLID";
// Get results ---------- count ----------------
$sql_result_counttotal = mysql_query($sql_counttotal,$connection) or die (" Could not get count! of TOTAl");
$sql_result_countambiance = mysql_query($sql_countambiance,$connection) or die (" Could not get count! of Ambiance");
$sql_result_countservice = mysql_query($sql_countservice,$connection) or die (" Could not get count! of Service");
$sql_result_countfood = mysql_query($sql_countfood,$connection) or die (" Could not get count! of Food");
$sql_result_countvalue = mysql_query($sql_countvalue,$connection) or die (" Could not get count! of Value");
// Get results ---------- sum ----------------
$sql_result_sumambiance = mysql_query($sql_sumambiance,$connection) or die (" Could not get sum! of Ambiance");
$sql_result_sumservice = mysql_query($sql_sumservice,$connection) or die (" Could not get sum! of Service");
$sql_result_sumfood = mysql_query($sql_sumfood,$connection) or die (" Could not get sum! of Food");
$sql_result_sumvalue = mysql_query($sql_sumvalue,$connection) or die (" Could not get sum! of Value");
// extract results ---------- count ----------------
$counttotal = mysql_result($sql_result_counttotal,0,"count(POLLID)");
$countambiance = mysql_result($sql_result_countambiance,0,"count(Ambiance)");
$countservice = mysql_result($sql_result_countservice,0,"count(Service)");
$countfood = mysql_result($sql_result_countfood,0,"count(Food)");
$countvalue = mysql_result($sql_result_countvalue,0,"count(Value)");
// extract results ---------- sum ----------------
$sumambiance = mysql_result($sql_result_sumambiance,0,"sum(Ambiance)");
$sumservice = mysql_result($sql_result_sumservice,0,"sum(Service)");
$sumfood = mysql_result($sql_result_sumfood,0,"sum(Food)");
$sumvalue = mysql_result($sql_result_sumvalue,0,"sum(Value)");
// The Math
$avgambiance = $sumambiance / $countambiance;
$avgservice = $sumservice / $countservice;
$avgfood = $sumfood / $countfood;
$avgvalue = $sumvalue / $countvalue;
$overall = ($sumambiance + $sumservice + $sumfood + $sumvalue)/4;
// format math
$fmt_avgambiance = sprintf("%0.1f",$avgambiance);
$fmt_avgservice = sprintf("%0.1f",$avgservice);
$fmt_avgfood = sprintf("%0.1f",$avgfood);
$fmt_overall = sprintf("%0.1f",($overall / $counttotal)) ;
$fmt_avgvalue = sprintf("%0.1f",$avgvalue);
$fmt_avgvaluebar = ($fmt_avgvalue * 10);
$fmt_avgfamily = sprintf("%0.1f",$avgfamily);
$fmt_avgfamilyno = sprintf("%0.1f",(100 - $avgfamily ));
$fmt_avgagain = sprintf("%0.1f",$avgagain);
$fmt_avgagainno = sprintf("%0.1f",(100 - $avgagain ));
$num = $num + 1;