I am developing a php website and need to fetch some data from previous month. Not only first previous month but last five months data. And I am confused that how can I do this? In my database I've created two columns. One is "Month" and another is "Year". So row will look like
id ---- text ---- month ---- year
1 ---- hello ---- May ----- 2014
2 ---- hi ---- May ----- 2014
Now I can fetch data by using date() function like this.
$first_month = date('F', strtotime('-1 month'));
$second_month = date('F', strtotime('-2 month'));
$third_month = date('F', strtotime('-3 month'));
for five months, I can create five variables. But for year? I mean if current month is january and year 2014, then I will need to fetch data from December 2013, so how it will work? Can anyone suggest me?
I am so confused. Please tell me if anyone has done something like this before. I need idea or concept.