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:

function mmmr($array, $output = 'mean'){ 
        return FALSE; 
            case 'mean': 
                $count = count($array); 
                $sum = array_sum($array); 
                $total = $sum / $count; 
            case 'median': 
                $middle = round(count($array) / 2); 
                $total = $array[$middle-1]; 
            case 'mode': 
                $v = array_count_values($array); 
                foreach($v as $k => $v){$total = $k; break;} 
            case 'range': 
                $sml = $array[0]; 
                $lrg = $array[0]; 
                $total = $lrg - $sml; 
        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 :)


Recommended Answers

All 4 Replies

Member Avatar for stbuchok

You could load everything into a JavaScript object (or array of javascript objects, whatever), however you need to know how much data that is.
Making a webservice call is not that bad and if it is a lot of data to go through, the server will probably handle it better.
You really haven't given enough information to make a decission as to what you should use.
How often is the data refreshing?
How often do you need to query for the data?
How long does it take to do the calculation on the server vs on the client?
Is there sensitive data that you don't want exposed to the client?


The table in question holds about 37 000 rows and is updated daily with about 7 new rows daily.

The user would probably query the data 6-8 times and there is no sensitive data to worry about.

To me it sounds like using a javascript object could get the work done? Base on my added info above, would you still say it's an option?


Member Avatar for stbuchok

If you are going to be returning 37000 records, I'd do all the calculations on the server side. Server side languages have more functionality to do calculations and will probably be easier to write, maintain and speed should be quicker.

Just my 2 cents.

Thanks for your input!! I'll keep it serverside for now :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.