Skip to content

Instantly share code, notes, and snippets.

@kylejohnson
Created November 30, 2012 13:48
Show Gist options
  • Save kylejohnson/4175821 to your computer and use it in GitHub Desktop.
Save kylejohnson/4175821 to your computer and use it in GitHub Desktop.
PHP Fatal error: [] operator not supported for strings
<?php
$dbhost="localhost";
$dblogin="house";
$dbpwd='password';
$dbname="house";
$db = mysql_connect($dbhost,$dblogin,$dbpwd);
mysql_select_db($dbname);
// 1. Get all of the sensors. ID, Name, Serial Number? (correctly associate Name => Number)
// 2. Get all of the times for $date
// 3. Get sensorname, temperature where date = $date
// 4. Hash of hashes!
// $data = [
// '12:01' = [
// 'Workshop' = 79,
// 'Computer Room' = 80,
// 'Kitchen' = 81
// ],
// '12:02' = [
// 'Workshop' = 80,
// 'Computer Room' = 82,
// 'Kitchen' = 78
// ],
// Every distinct hour
$query_time = "select distinct concat(time_format(from_unixtime(statDate), '%h'), time_format(from_unixtime(statDate), '%p')) as Date from stats where date(from_unixtime(statDate)) = curdate()";
$result_time = mysql_query($query_time) or die ('query failed: ' . mysql_error());
while ($time = mysql_fetch_array($result_time)) {
$times[] = $time;
}
// Find all of the sensors
$query_rooms = 'select distinct SensorID, SensorName from sensors';
$result_rooms = mysql_query($query_rooms) or die ('query failed: ' . mysql_error());
// Put all of the sensors from the above query into an array
while ($row = mysql_fetch_array($result_rooms)) {
$rooms[$row[0]] = $row[1];
}
while ($room = current($rooms)) {
$$room = $room;
$roomid = key($rooms);
$query = "select statValue from stats where date(from_unixtime(statDate)) = curdate() AND SensorID = $roomid order by StatDate ASC";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
while ($row = mysql_fetch_array($result)){
${$room}[] = $row[0];
}
next($rooms);
}
mysql_close($db);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment