$value) { if (in_array($key, $rfields)) { $dataTypes[] = $key; } } // Did we get any valid parameters? if (count($dataTypes) == 0) { die('No valid return data types supplied'); } // Connect to the datbase $con = mysql_connect($dbhost, $dbuser, $dbpassword); if (!$con) { die('Failed to connect to the database server'); } if (!mysql_select_db($database, $con)) { die('Failed to connect to the database on the server'); } $result = mysql_query('SET time_zone="+0:00"'); if (!$result) { die('ERROR - TZ Statement'); } // Was the 'nth' parameter supplied? If not, do a standard query, else, only return every nth row from the table if ($nth === '') { // Start of query string, then... $query = 'SELECT UNIX_TIMESTAMP(LogDateTime)'; //$query = 'SELECT LogDateTime'; // add query data columns, then.. foreach($dataTypes as $key) { $query .= ', ' . $key; } // end of query string. $query .= " FROM $logtable WHERE LogDateTime > DATE_SUB($strtd, INTERVAL $recordAge $recordUnit) and LogDateTime < DATE_ADD($strtd, INTERVAL 1 day) ORDER BY LogDateTime ASC"; } else { // Only return every nth row // Start of query string, then... $query = 'SELECT ts'; // add query data columns, then.. foreach($dataTypes as $key) { $query .= ', ' . $key; } $query .= ' FROM ( SELECT @row := @row +1 AS rownum, UNIX_TIMESTAMP(LogDateTime) AS ts'; // add query data columns, then.. foreach($dataTypes as $key) { $query .= ', ' . $key; } // end of query string. $query .= " FROM $logtable WHERE LogDateTime > DATE_SUB($strtd, INTERVAL $recordAge $recordUnit) ORDER BY LogDateTime ASC) as DT WHERE MOD(rownum,$nth)=0"; // initialise the row counter $result = mysql_query('SET @row := 0;'); if (!$result) { die("ERROR - Bad SQL Statement: $query"); } } // Perform query $result = mysql_query($query); if (!$result) { die("ERROR - Bad Select Statement: $query"); } // for each of the returned rows, put the data into a series of arrays... while($row = mysql_fetch_row($result)) { $tim = $row[0] * 1000; $i = 1; foreach($dataTypes as $key) { ${"arr_$key"}[] = array($tim, (float)$row[$i++]); } } // build the return array foreach($dataTypes as $key) { $return[$key] = ${'arr_' . $key}; } header('Cache-Control: private'); header('Cache-Control: no-cache, must-revalidate'); header('Content-type: text/json charset=UTF-8'); // encode the result and echo it back to the client echo json_encode($return); // ========== End of Module =========== ?>