MySQL Forums
Forum List  »  PHP

myPHAdmin give different results than PHP select
Posted by: Brian Witowski
Date: May 01, 2017 09:10PM

Greetings,

I'm a newbie so please bear with me. I am working with an RPi and 'inserting' into a MySQL database from Python. That part works fine.

Forgive me if I give you too much info but I want things to be in context so you can understand my configuration.

Using my RPi, (Raspberry Pi 3 B) I read temp, humidity and barometric pressure sensors and insert them into my DB called 'weather'. I then query a table called 'WEATHER_MEASUREMENTS' to display various data in a website hosted locally using lighttpd.

One of the things I wish to display is the last 24 hours of barometric pressure.

I currently insert temperature, humidity and barometric pressure into my DB once every 10 minutes. In order to display weather trends I wish to show barometric pressure readings over 24 hours. Since I take 6 readings per hour, I wanted limit it to ten readings over 24 hours, equally spaced. I took this to be equivalent to 'mod 14'. I wish to display to two columns, 'AIR_PRESSURE' and 'CREATED'. CREATED is a 'timestamp' column.

I have two files I work with; my index.php and readings.html.php. At the end of the index.php file is an 'include' line that reads: include 'readings.html.php';

My initial query is done in the index.php and looks like this:

$result = mysqli_query($link, 'Select ID, CREATED, DATE(CREATED), AIR_PRESSURE
FROM WEATHER_MEASUREMENT WHERE mod(ID,14) = 0 GROUP BY CREATED ORDER BY ID DESC LIMIT 10');
if (!$result)
{
$error = 'Error fetching date : ' . mysqli_error($link);
include 'error.html.php';
exit();
}

while ($row = mysqli_fetch_array($result))
{
$prevdaypress[] = $row['AIR_PRESSURE'];
$prevdaytime[] = $row['CREATED'];
}
$testarray=array_combine($prevdaypress, $prevdaytime);

Then in my 'readings.html.php' I have this:

<?php foreach ($testarray as $prevdaystuff): ?>
<?php echo ($prevdaystuff)?><br>
<?php endforeach; ?>

And this is my output on my web page:

2017-05-01 17:58:33
2017-05-01 15:37:53
2017-05-01 13:17:19
2017-05-01 10:56:37
2017-05-01 08:35:47
2017-05-01 06:14:54
2017-04-30 23:13:43
2017-04-30 20:53:19

There are two things to note; the barometric pressure isn't in the list, which should be there from the line, '$prevdaypress[] = $row['AIR_PRESSURE'];'.

Also, notice the large gap between, '2017-04-30 23:13:43' and '2017-05-01 06:14:54'. The gap should only be a max of about 2.5 hours if you do the math.

I've tried a bunch of different combinations of this query, etc. and sometimes I have a date from April mixed in between two 'May dates'.

I hope I've provide enough information. I wanted to give a good idea of what I was doing and what I wanted to achieve. Your help is appreciated!

Options: ReplyQuote


Subject
Written By
Posted
myPHAdmin give different results than PHP select
May 01, 2017 09:10PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.