PHP

<?php

$rcn = mysql_connect("localhost","usr","pwd");

mysql_select_db("test");

$termid = " and `thermometerid` = 2";

$last = "order by `measurementdatetime`";

$from = "";

$to = "";

$funk = "MIN";

if (isset($_GET['termid'])) $termid=" and `thermometerid` = ".$_GET['termid'];

if (isset($_GET['last'])) $last="order by `measurementdatetime` desc, 'termid'

limit ".$_GET['last'];

if (isset($_GET['from'])) $from=" and `measurementdatetime` >= ".$_GET['from'];

if (isset($_GET['to'])) $to=" and `measurementdatetime` <= ".$_GET['to'];

if (isset($_GET['funk'])) $funk="".$_GET['funk'];

$sqlstr = "SELECT MIN(`javadatetime`) as javadatetime, ROUND(".$funk."(`value`),1) as value

FROM `temperatures`

WHERE 1 ".$termid." ".$from." ".$to."

group by TO_DAYS(`measurementdatetime`)

".$last;

$res = mysql_query($sqlstr);

$number = mysql_num_rows($res);

$first = false;

printf("[");

if ($number > 0)

{

while ($row=mysql_fetch_array($res)) {

if ($first) printf(",");

printf("[");

printf($row['javadatetime']);

printf(", ");

printf($row['value']);

printf("]");

$first = true;

}

}

printf("]");

mysql_close();

?>