Css-php displays articles in chronological order

Source: Internet
Author: User
The time field in the database is an int-type Timestamp. If you want to make the following effect, you have no experience. I hope you can give me some ideas. Thank you!

The time field in the database is an int-type Timestamp. If you want to make the following effect, you have no experience. I hope you can give me some ideas. Thank you!

Reply content:

The time field in the database is an int-type Timestamp. If you want to make the following effect, you have no experience. I hope you can give me some ideas. Thank you!

SQL = 'select * FROM 'table' ORDER BY created desc'; // your database driver logic // data processing if ($ articles) {$ res = []; foreach ($ articles as $ article) {$ year = date ('y', $ article ['created ']); $ res [$ year] [] = $ article; // year as an array index ,}} // The final output result is similar to this: $ res => [[2014] => [[0] => [// article 1], [1] => [// article 2], [2015] => [0] => [// article 1], [1] => [// article 2]

Order by time field name DESC // time from large to small order by time field name ASC // time from small to large

When you call an SQL statement, order by field_time desc is not finished.

I think it should be possible to refer to solutions similar to Paging

Is the time type conversion. Use strtotime
$ Dated is the timestamp you took out.
Date ("Y", strtotime ($ dated); // year
Date ("m/d", strtotime ($ dated); // month/day

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.