PHP MySQL How to implement the blog Monthly Archive

Source: Internet
Author: User
Tags echo date php mysql
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?

    1. I agree with the first view upstairs, the article table needs to have two fields, Create_month, create_month_time;

    2. 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

    3. Then a grouping group by and sort of order by done

    4. 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(                //文章信息                )            )        )
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.