If you want one line per measurement type, you need to pivot your data by measurements.title
. MySQL does not support the PIVOT
statement, so you have to fake it like this:
SELECT
routines.data,
routines.time,
SUM(IF(measurements.title = 'T_Badende_per_Time', , 0)) CAST(REPLACE(measurements.value, ',', '.') AS DECIMAL(18, 2)) as T_Badende_per_Time,
SUM(IF(measurements.title = 'measure_2', CAST(REPLACE(measurements.value, ',', '.') AS DECIMAL(18, 2)), 0)) as measure_2,
SUM(IF(measurements.title = 'measure_3', CAST(REPLACE(measurements.value, ',', '.') AS DECIMAL(18, 2)), 0)) as measure_3
etc...
FROM
routines
INNER JOIN measure_routine ON routines.id = measure_routine.routine_id
INNER JOIN measurements ON measure_routine.measure_id = measurements.id
WHERE
<conditions>
GROUP BY routines.date, routines.time
ORDER BY routines.date, routines.time
Then in PHP, create one column for each measurement type:
$table['cols'] = array(
array('label' => 'routines.date' & 'routines.time', 'type' => 'datetime'),
array('label' => 'T_Badende_per_Time', 'type' => 'number'),
array('label' => 'measure_2', 'type' => 'number'),
array('label' => 'measure_3', 'type' => 'number')
// etc
);
$rows = array();
while($r = mysql_fetch_assoc($sth)) {
$temp = array();
// assumes dates are in the format "yyyy-MM-dd"
$dateString = $r['date'];
$dateArray = explode('-', $dateString);
$year = $dateArray[0];
$month = $dateArray[1] - 1; // subtract 1 to convert to javascript's 0-indexed months
$day = $dateArray[2];
// assumes time is in the format "hh:mm:ss"
$timeString = $r['time'];
$timeArray = explode(':', $timeString);
$hours = $timeArray[0];
$minutes = $timeArray[1];
$seconds = $timeArray[2];
$temp = array();
$temp[] = array('v' => "Date($year, $month, $day, $hours, $minutes, $seconds)");
$temp[] = array('v' => (string) $r['T_Badende_per_Time']);
$temp[] = array('v' => (string) $r['measure_2']);
$temp[] = array('v' => (string) $r['measure_3']);
// etc..
$rows[] = array('c' => $temp);
}