php - Incremental MySQL Timestamp conversion for highstock -


i'm using highstock library show output data magnetometer, have little problem. store data in 2 fields in bd. first value datetime data saved, , second sensor value:

2015-06-10 01:29:43 | 15

but because sensor send more 1 value in 1 second, need convert time, unix in incremental way

let's suppose it's raw data:

2015-06-10 01:29:43 | 15 2015-06-10 01:29:43 | 16 2015-06-10 01:29:43 | 40 2015-06-10 01:29:43 | 50 2015-06-10 01:29:43 | 15 2015-06-10 01:29:43 | 11

i convert timestamp:

1444094983 | 15 1444094983 | 16 1444094983 | 40 1444094983 | 50 1444094983 | 15 1444094983 | 11

the last step convert time milliseconds. it's not problem. thing is, need every second repeated, have incremental millisecond this

1444094983001 | 15 1444094983002 | 16 1444094983003 | 40 1444094983004 | 50 1444094983005 | 15 1444094983006 | 11

but when new second begins, incremental number must restarted , start 0 again.

i'm working php , way solve it

$i = 1; foreach ($row $result){     $row['data_logged'] * 1000 + $i; // assuming converted in mysql unix_timestamp     if($prev_data != $row['data_logged']) $i = 1;     $prev_data = $row['data_logged'];     $i++; } 

there better/simplest way it?

alternative design proposal based on discussion:

there auto increment option in mysql, option takes care every inserted record has unique key. using option, data can stored without having have alternate code in php:

create table magnometerdata( mmdata_id int not null auto_increment, mmrecordtime timestamp, value double ) engine=innodb row_format=compressed key_block_size=4k; 

inserting data in table, leads record follows:

1,1444094983001,{your measured value}

2,1444094983002,{another measured value} etc

so key keeps unique. key has no other function in data keep unique , run order on it.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -