Not sure if the subject is suitable for the question.
I have a table which holds some data with year info as shown below.
table mydata
+----+------------+----------+
| id | year | some_data|
+----+------------+----------+
| 1 | 2011 | x |
| 2 | 2012 | y |
| 2 | 2009 | x |
| 2 | 2007 | z |
| 1 | 2009 | b |
| 3 | 2011 | a |
| 2 | 2007 | n |
| 3 | 2006 | h |
| 2 | 2007 | t |
+----+------------+----------+
Here is my problem. I'm trying to fetch data of certain id from mydata table with year information. However I need to show records in range of certain years, like past 6 years and next 6 years of present.
For example;
id = 2
+----+------------+----------+
| id | year | some_data|
+----+------------+----------+
| 2 | 2007 | z |
| 2 | 2007 | n |
| 2 | 2009 | x |
| 2 | 2012 | y |
+----+------------+----------+
And I need to show data like that in HTML table structure:
+------------+----------+
| year | some_data|
+------------+----------+
| 2006 | |
| 2007 | z |
| | n |
| | t |
| 2008 | |
| 2009 | x |
| 2010 | |
| 2011 | |
| 2012 | y |
| 2013 | |
| 2014 | |
| 2015 | |
| 2016 | |
| 2017 | |
| 2018 | |
+------------+----------+
I don't know in which year there are duplicated records and which years are absent. So I always try my solutions with more than one queries or lots of for loops. And doesn't work as I desired.
And ideas?