Trying to find the median for an array in a MYSQL database.
Currently, I am grabbing my data like so:
$middleMonth = "SELECT Day, COUNT(Day) AS totalNumber FROM finalbaby GROUP BY Day ORDER BY COUNT(Day) DESC LIMIT 1, 300";
$middleResult = mysql_query($middleMonth);
I am then putting it into an array like so.
$names=array();
while($row = mysql_fetch_assoc($middleResult)) {
$names[] = $row['Day'];
I am then trying to find the median of that array:
sort($names);
$count = count($names);
$middleval = floor(($count-1)/2);
if($count % 2) {
$median = $names[$middleval];
} else {
$low = $names[$middleval];
$high = $names[$middleval+1];
$median = (($low+$high)/2);
}
return $median;
}
var_dump($names);
I am not getting any errors, but it crashes my application.
Any suggestions on what I am doing wrong?