Actually, if an AUTO_INCREMENT index field (i.e. my suggested 'id' field) is used, then one will not need to record a timestamp, since the id will provide the same functionality.
To find the average in an array of numbers, $num_array,
Arithmetic mean:
$mean = array_sum($num_array) / count($num_array);
though you might have to check that the array has values, or you will get a division by 0 runtime error.
Median:
sort($num_array);
$num = count($num_array);
if ($num % 2 == 0) {
//array has even number of values
$num /= 2;
$median = ($num_array[$num] + $num_array[$num-1]) / 2;
}
else {
//array has odd number of values
$num = ($num - 1) / 2;
$median = $num_array[$num];
}