<?php

print "<meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\">";

$DATA_TABLE = "lazurite.data_log";
$HOST = "192.168.100.153";
$DB = "arduino";
$USER = "postgres";
$PASS = "postgres";

$conn = pg_connect("
	host	=	". $HOST. "
	dbname	=	". $DB. "
	user	=	". $USER. "
	password=	". $PASS. "
");

$sel = "SELECT * FROM lazurite.data_log WHERE datetime > '2018-11-05 16:18' ORDER BY datetime desc";
$res = pg_query($conn,$sel);
$ct = pg_num_rows($res);

print "<TABLE BORDER='1'><TR ALIGN='center'><TD>日時</TD><TD>水深(m)</TD></TR>";
for($ii = 0 ;$ii < $ct;$ii++)
{
	$row = pg_fetch_array($res,$ii);
	print "<TR><TD  width='150'>";
	print date("Y-m-d H:i" ,strtotime($row[0]));
	print "</TD><TD width='70' ALIGN='right'>";
//	print number_format($row[1],"5","." ,"");
	$calc_data = number_format(($row[1] - 0.782) /0.0622,"1","." ,"");
	
	if($calc_data == -0.0) $calc_data = "0.0";
	
	print $calc_data;
	
	print "</TD></TR>";
}


print "</TABLE>";
?>