PHP MySQL How to implement the blog Monthly Archive
Reply content:
PHP MySQL How to implement the blog Monthly Archive
1. First need the structure of your data table to support, usually the article records management should exist create_time
, update_time
such as sub-fields.
2. With these fields, we can classify them according create_time
to
The functions for processing timestamps in 3.PHP timestamp
are
strtotime()
The function resolves the date or time description of any English text to a Unix timestamp (the number of seconds from January 1 1970 00:00:00 GMT).
date()
Formatting timestamps
You can use
time()
Represents the current UNIX timestamp
Gets the current month output to10
Gets the current date output as2016-10-08
You can use $article_time = strtotime($create_time_timestamp)
to get to the format date created by your article time()
,
Then use the
get created month to archive the output!
Of course, it would be better if you had archived the article when it was stored in the database!
Table in the redundant archived fields, save the month of the blog. This is convenient!
Isn't it a little complicated upstairs?
I agree with the first view upstairs, the article table needs to have two fields, Create_month, create_month_time;
The above two fields are saved in the format of the article creation month, create_month
format: 2016-10
, then the timestamp of the month is create_month_time
stored
Then a grouping group by
and sort of order by
done
Can put the query out of the data, a little assembled, organized into the following array format:
$article_list = array( '2016-10' => array( 0 => array( //文章信息 ), 1 => array( //文章信息 ) ), '2016-9' => array( 0 => array( //文章信息 ), 1 => array( //文章信息 ) ) )