I have a table in a MySQL database that I have tried to create to be flexible in terms of the information it can store. The idea is that lots of test information gets put into this table, and then I can query the table and output into PHP to undertaken analysis on the data.
The table schema is as follows; idraw_data (auto increment) entry_date (datetime) SensorID (int) test_ID (int) test_value (double)
I use two other tables as well which link into SensorID and Test_ID. One lists the location and information about the specific sensor (e.g. who it is assigned to), and the other table includes test information like what the test is measuring, units, upper and lower limits and so on.
So i have a join statement working which lets me get the data in the form of the date, desk, test name and value filtered by mon-fri (9am - 5pm)which is the query below;
SELECT raw_data.entry_date, SensorID.Desk, tests.testname, raw_data.test_value FROM raw_data INNER JOIN sensorID ON raw_data.sensorID = SensorID.Sensor INNER JOIN tests ON raw_data.test_id = tests.testid WHERE WEEKDAY(raw_data.entry_date) BETWEEN 0 AND 4 AND HOUR(raw_data.entry_date) BETWEEN 9 AND 17;
I can use a PHP query and get the database output, and then use json_encode to put this into a JSON string to then feed into a graphing package amcharts but where I am struggling is how I can format the data to be more usable.
Is someone able to show me how I can format the mysql output to subsequently be able to get a json schema similar that provides the date & time, then the measurement type and value dynamically,
e.g. date, {location; locationname, [testa:testaname_value, testbname;testbvalue}} or is there a better way to output this for ease of graphing?
Many thanks!