<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<title>Temperature_2</title>
		<meta name="author" content="Gábik Matej">
		<meta charset="UTF-8">
		<meta name="DP_BUSE BS210" content="index, follow">
		<meta name="description" content="Temperature_1">
		<meta name="keywords" content="HTML, BS210, MeteoStanica">
		<link rel="stylesheet" href="test.css" type="text/css">
		<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
		<style type="text/css">
		${demo.css}
		</style>
		<style>
		table, th, td {
		     border: 1px solid black;
		     text-align: center;
		     margin-left: auto;
		     margin-right: auto;
		     width: 40%;
		}
		</style>

	        <style>
	             table, th, td {
                     border: 1px solid black;
                     text-align: center;
                     margin-left: auto;
                     margin-right: auto;
                     width: 40%;
                }

                </style>

		<script type="text/javascript">
		$(function () {
			$('#container').highcharts({
				title: {
					text: 'Average Temperature',
					x: -20 //center
				},
				xAxis: {
				//	categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
				//		'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
					categories: myLabels
				},
				yAxis: {
					title: {
						text: 'Temperature (°C)'
					},
					plotLines: [{
						value: 0,
						width: 1,
						color: '#808080'
					}]
				},
				tooltip: {
					valueSuffix: '°C'
				},
				legend: {
					layout: 'vertical',
					align: 'right',
					verticalAlign: 'middle',
					borderWidth: 0
				},
				series: [{
				//	name: ' ',
				//	data: [10, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6]
					data: myData
				}]
			});
		});
		</script>

		 <?php
    /* Open connection to "zing_db" MySQL database. */
    $mysqli = new mysqli("localhost", "matej", "database112", "data");

    /* Check the connection. */
    if (mysqli_connect_errno()) {
        printf("Connect failed: %s\n", mysqli_connect_error());
        exit();
    }

    /* Fetch result set from t_test table */
    $data=mysqli_query($mysqli,"SELECT * FROM sensor_data");
    ?>

                 <script>
                    var myData=[<?php
                    while($info=mysqli_fetch_array($data))
                        echo $info['temp2'].','; /* We use the concatenation operator '.' to add comma delimiters after each data value. */
                    ?>];
                    <?php
                    $data=mysqli_query($mysqli,"SELECT ttime FROM sensor_data");
                    ?>
                    var myLabels=[<?php
                    while($info=mysqli_fetch_array($data))
                        echo '"'.$info['ttime'].'",'; /* The concatenation operator '.' is used here to create string values from our database names. */
                    ?>];
                </script>


	</head>
<body>
	<h1 align="center">Temperature from senzor HIH6130</h1>
	
	<hr>
	<nav align="center">
	<ul>
		<li><a href="index.php"><b>Introduction</b></a></li> <!-- Dostaneme sa na úvodnú stránku -->
		<li><a href="#"><b>Weather Station</b></a>
			<ul>
				<li><a href="temperature_1.php">Temperature 1</a></li>		<!-- Prepene sa na novú stánku kde budú zmerané údaje s teplomera číslo 1 -->
				<li><a href="temperature_2.php">Temperature 2</a></li>		<!-- Prepene sa na novú stánku kde budú zmerané údaje s teplomera číslo 2 -->
				<li><a href="temperature_3.php">Temperature 3</a></li>		<!-- Prepene sa na novú stánku kde budú zmerané údaje s teplomera číslo 3 -->
				<li><a href="humidity.php">Humidity</a></li>
				<li><a href="press.php">Pressure</a></li>
			</ul>
		</li>
		<li><a href="#"><b>Display BUSE BS210</b></a>
			<ul>
				<li><a href="basic_info.php">Basic Info</a></li>
				<li><a href="canvas.html">Basic Control Display</a></li>
				<li><a href="#">Timetable</a></li>
			</ul>
		</li>
	</ul>
	</nav>
	<hr>

<?php
$servername = "localhost";
$username = "matej";
$password = "database112";
$dbname = "data";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT tdate, ttime, temp2 FROM sensor_data ORDER BY ttime,tdate DESC LIMIT 20";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    echo "<table><tr><th>Date</th><th>Time</th><th>Temperature [°C]</th></tr>";
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo "<tr><td>".$row["tdate"]."</td><td>".$row["ttime"]."</td><td>".$row["temp2"]."</td></tr>";
    }
    echo "</table>";
} else {
    echo "0 results";
}
$conn->close();
?>





	<script src="highcharts.js"></script>
	<script src="exporting.js"></script>

	<div id="container" style="min-width: 310px; height: 500px; margin: 0 auto"></div>

</body>
</html>
