I have a very simple online program that permits a user to enter data several times a day. I'd like to permit the user to look at his or her own data in some new ways.
The actual data is very personal to the user so I'll use outdoor temperature readings as a way to frame my question. I'm using PHP 5 and MySQL.
Suppose user George has provided the following entries:
April 1; 9:05 a.m.; 60 degrees;
April 2; 6:10 a.m.; 55 degrees;
April 2; 9:00 a.m.; 68 degrees;
April 2; 10:15 a.m.; 72 degrees;
April 5; 8:58 a.m.; 48 degrees;
April 10; 9:02 a.m.; 70 degrees.
April 14; 8:55 a.m.; 62 degrees.
I'd like for the user to be able to get an average reading for the hours from 6 a.m. to 12 noon during the period April 1 to April 14.
I can probably write a query that would enable George to do that except that I'm not sure how to deal with the multiple readings for April 2nd. I'd want to average the 3 readings for April 2nd, which would yield a value of 65; and then use 65 as the 'entry' for that day when averaging across the entire two-week period.
My original idea was to use a PHP conditional to identify which days have multiple entries, and address those in an if conditional; and then deal with single entry days in the else clause. And then I'm not sure -- assign the values to an array and average them in that form? However, I'm told that that is an awkward and inefficient approach and have been generally discouraged from trying it. At the moment, I'm left with no ideas at all.
I'm doing this partly as a learning exercise and so I'm not asking anyone to write the code. Can someone give me an idea of where to start? If you can give me some of the vocabulary, I'll research it myself and see if I can come up with something.
I'm hoping for a simple solution that I'll be able to understand and implement. Right now an inefficient solution that I can use will be better than an efficient one that is too sophisticated for me and that I can't use.
Many thanks for any help you can give me with this.