hi, i have some problem with my php script. i want to sum all value in my table field, here it is the field that i have: table name examVal ratingValue ---- int(2) Tony -------------5 Linda -------------9 Burhan -----------7 Darsimin ----------10 Tukiyem ----------4 Bajeneh ----------9 And here the is query $queryRating = mysql_query ("select int from examVal",$connection) or die (mysql_error()); PHP: And now my question is: how to get a value like this (what is the script): 5+9+7+10+4+9=44, should it use array? Best Ragards S.Junandya
$queryRating = mysql_query ("select sum(ratingValue) from examVal",$connection) or die (mysql_error());
MySQL has what's known as Aggregate Functions. The function you're looking for is SUM. You might want to use an alias for the result of the function, it makes it easier to reference. SELECT SUM(column) as column_sum FROM table_name Code (markup): // Assume $row is the result row here $sum = $row['column_sum']; PHP: