0

I have a strange problem relating to a PHP array, that I am struggling to diagnose. I have a script that reads temperatures from a SQL db and then displays them via PHPgraphlib. I take the unix epoch time stamp from the database query and convert into human readable form. This is used as a key in the array that stores the temperatures. So, in summary I have the following in a loop

$unix_time = $row['DATE_TIME'];
$human_date = date("md.h:i",$unix_time);
$temp_array[$human_date] = $row['CURRENT_TEMP'];

I then display the results, using phpgraphlib:-

$graph->addData($temp_array);

This displays the temperatures on the y axis vs the human readable timestamps on the x.

This seems to work fine, until 12 midday, when it stops displaying data with a timestamp after 1200, it then restarts after 0000. Which is very strange. Similarly, if I just use the unix epoch timestamp (something like 1459799541) as the key, do data is displayed.

Is there a limit to the length of the key that I am excessing after midday/with the long unix epoch time? Any help greatly appreciated!

noodles
  • 5
  • 1
  • 3
    I don't know `phpgraphlib`, but `h` is 1-12 so 12 noon and 12 midnight are the same as are all of the other AM and PM times. This makes duplicate keys which are not allowed. Try using `H` for 24 hour time and see if it works. – AbraCadaver May 06 '16 at 15:51
  • Good old print_r and have a look at your array. You can double check AbraCadaver's suggestion – James Dewes May 06 '16 at 15:58
  • And....... The verdict is? – AbraCadaver May 06 '16 at 19:51
  • Thanks, yes it was the 12 hour clock, changing h to H, solved it. Ijust got around to changing my script today, thanks for the help. – noodles May 08 '16 at 11:07

1 Answers1

1

I don't know phpgraphlib or what it expects for data, but h is 12 hour time needing AM or PM to distinguish. 12 PM (noon) and 12 AM (midnight) are the same as are all of the other AM and PM times. This may make duplicate keys which are not allowed so you only get one. Also, phpgraphlib may be getting confused if it gets data from 12-11 and then 12 again.

Try using H for 24 hour time and see if it works "md.H:i".

Not sure why the timestamp isn't working.

AbraCadaver
  • 78,200
  • 7
  • 66
  • 87