Any PHP gurus around here?

Kreskin

Doctor of Thinkology
Feb 23, 2006
21,155
149
63
I know you're out there. I want to be able to calculate the median as well as the mean. The mean is already working but I don't know how to have the script determine the median. If you are a php wizard give me a shout.

<?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>";
?>
 

Kreskin

Doctor of Thinkology
Feb 23, 2006
21,155
149
63
OK I figured out an easy way to calculate and show the median average of an unordered database list. One that actually works (and did I say it's so damn easy). I'm surprised how little success there is with that programming function in PHP webmaster forums. So all those PHP gurus who find this thread via google can beg me for the code. No guarantees I'll be nice.
 

Kreskin

Doctor of Thinkology
Feb 23, 2006
21,155
149
63
I think the only thing that could be done is sell it as a software package, but that won't happen. I don't think there's any legal way to prevent anyone from using programming code. I'm just surprised I came up with a fix by trial and error that is much more simplistic than what I've seen talked about.