<?php // Connects to your Database
mysql_connect("localhost", "database") or die(mysql_error());
mysql_select_db("database_extension") or die(mysql_error());
$handle = mysql_query("SELECT SUM(field) AS myvalue FROM table WHERE field >=1 ");
// Check to see if we did something wrong
if( !$handle ) {
die( 'Error running query: ' . mysql_errno( $handle ) . ' ' . mysql_error( $handle ) );
}
// Fetch the row
$row = mysql_fetch_assoc( $handle );
// Grab the data we want out of the row
echo "Sum of field = ";
echo $myvalue = $row['myvalue'];
print "<br>";
// number of rows
$result = mysql_query("SELECT * FROM table WHERE field >=1 ");
$num_rows = mysql_num_rows($result);
echo "Number in field = ";
echo "$num_rows";
print "<br>";
$average = $myvalue/$num_rows;
echo "Average beta reported = ";
printf("%.0f", "$average");
//adding average
$results = mysql_query("SELECT * FROM table WHERE field >=1 AND otherfield>=1");
$num_rows = mysql_num_rows($results);
print "<br>";
echo "Average = ";
echo "$num_rows";
print "<br>";