1

This might be a weird question but let me try to explain best I can.

I have a table in my database and this table contains N number of records the table is simple its laid out as follows:

ID, Time, Data

So the end goal is to out put a Graph for a yearly period based off the values in this table. Now this wouldn't usually be such a big deal but the values in the table are limitless for a year, but there is no pattern to how frequent these will be entered.

In theory the person responsible for updating this table will be doing it once per 2 weeks but this can not be relied upon because I know they wont, so I want to dump all the values from the table then create and array from the results with only 2 values per month one for the 14th and one for the 28th so this will cover all months.

Anyway so I figure,

Select * FROM table
For each 
.... take value closest to 14th 
.... take value closest to 28th 
.... Dump each into new array

But how would you go about doing this in PHP I can't work out how you would get the closest value to each day for that month only and limit it to 2, the hard thing for me is getting my head around if they didn't update it in say 4 weeks what then? use the last value I guess.

Has anyone done this before?

Someone
  • 894
  • 3
  • 22
  • 43
  • Some of this: http://stackoverflow.com/questions/12113699/get-top-n-records-for-each-group-of-grouped-results with extra logic to handle the "closest to desired data" business as well – Marc B Nov 25 '13 at 16:30
  • So I can achieve this with pure SQL? I wont even need to use PHP? – Someone Nov 25 '13 at 16:37
  • I have no idea :/ I am clearly less skilled with SQL than I thought that question he linked me too is way over my head. – Someone Nov 25 '13 at 16:59

0 Answers0