Skip to content

Instantly share code, notes, and snippets.

@flavio-fernandes
Created January 13, 2020 11:24
Show Gist options
  • Save flavio-fernandes/079d3351bf5d4d36367a743051a0cafe to your computer and use it in GitHub Desktop.
Save flavio-fernandes/079d3351bf5d4d36367a743051a0cafe to your computer and use it in GitHub Desktop.
potofjoy db php
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script src="http://code.jquery.com/jquery-1.9.1.js" type="text/javascript"></script>
<script src="http://code.highcharts.com/highcharts.js" type="text/javascript"></script>
<script src="http://code.highcharts.com/modules/exporting.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
var chart;
$(document).ready(function() {
$.getJSON("graph_data.php", function(json) {
chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
type: 'line',
marginRight: 130,
marginBottom: 25
},
title: {
text: 'Temperatures',
x: -20 //center
},
subtitle: {
text: '',
x: -20
},
xAxis2: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
yAxis: {
title: {
text: 'Amount'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
tooltip: {
formatter: function() {
return '<b>'+ this.series.name +'</b><br/>'+
this.x +': '+ this.y;
}
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
x: -10,
y: 100,
borderWidth: 0
},
series: json
});
});
});
});
</script>
</head>
<body>
<div id="container" style="width: 100%; height: 800px; margin: 0 auto"></div>
</body>
</html>
<?php
$con = mysql_connect("db.potofjoy.com", "cranberry", "readOnlyRO") or die("Não foi possível conectar: " . mysql_error());
mysql_select_db("temp_monitor");
$result = mysql_query("select temperature from temperatures where location='outside' and timestamp >= from_days(to_days(now()) - 30) order by timestamp");
$rows1 = array();
$rows1['name'] = 'Outside';
while ($r = mysql_fetch_array($result)) {
$rows1['data'][] = $r['temperature'];
}
$result = mysql_query("select temperature from temperatures where location='house' and timestamp >= from_days(to_days(now()) - 30) order by timestamp");
$rows2 = array();
$rows2['name'] = 'House';
while ($r = mysql_fetch_array($result)) {
$rows2['data'][] = $r['temperature'];
}
$alldata = array();
array_push($alldata,$rows1);
array_push($alldata,$rows2);
print json_encode($alldata, JSON_NUMERIC_CHECK);
mysql_free_result($result);
mysql_close($con);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment