Hi,
So far in me slowly learning webdevelopement (mostly thanks to all of you guys) I've used php to query the mysql database to calculate mean/mode/range/median values and to create arrays to visualize with highgraph.
Now I've come to a point where I really need if possible, to skip the serverside proccessing so no page refresh is neccacary after the initial load.
So, I've got a highstock chart that looks like this: http://jsfiddle.net/gh/get/jquery/1.7.2/highslide-software/highcharts.com/tree/master/samples/stock/rangeselector/input-datepicker/
But instead of using json as in the example I have php variables.
Ideally I would like to use the date range from the highstock chart to applay to my other "calculations" so for example the mean value shown is allways depending on the highstock date range.
This is how I calculate the mean value today:
<?php
function mmmr($array, $output = 'mean'){
if(!is_array($array)){
return FALSE;
}else{
switch($output){
case 'mean':
$count = count($array);
$sum = array_sum($array);
$total = $sum / $count;
break;
case 'median':
rsort($array);
$middle = round(count($array) / 2);
$total = $array[$middle-1];
break;
case 'mode':
$v = array_count_values($array);
arsort($v);
foreach($v as $k => $v){$total = $k; break;}
break;
case 'range':
sort($array);
$sml = $array[0];
rsort($array);
$lrg = $array[0];
$total = $lrg - $sml;
break;
}
return $total;
}
} ?>
<?php //-- medeltal -->
$trackingquery = mysql_query("SELECT * FROM lime_survey_345541");
if ($trackingquery) {
$arr = array();
while ($row = mysql_fetch_array($trackingquery)) {
if ($row['262697X5X7'] > 0) {
$arr[] = $row['262697X5X7'];}
}
} else {
print('MySQL query failed with error: ' . mysql_error());
}
?>
and the i just echo <?php echo 'Medeltal: '.number_format(mmmr($arr), 2, ',', ' ').''; ?>
My best bet in how to go about this would be to load the entire table in question to json or ajax and the depending on the date range from the chart then calculate for example the mean values in ajax somehowe?!
So is this possible and if so, maybe you could give me a push in the right direction :)
Sinceraly
/Adam