Css-php displaying articles based on chronological order

Source: Internet
Author: User

Database inside Time word Gencun is int type time stamp, want to make below this effect, have no experience, hope everybody can give a thought, thank!

Reply content:

Database inside Time word Gencun is int type time stamp, want to make below this effect, have no experience, hope everybody can give a thought, thank!

sql = 'SELECT * FROM `table` ORDER BY created DESC';//你的数据库驱动逻辑//数据处理if ($articles) {    $res = [];    foreach ($articles as $article) {        $year = date('Y', $article['created']);        $res[$year][] = $article; //以年为单位,作为数组索引,    }}//最后输出结果类似这样$res => [    [2014] => [        [0] => [            //article 1        ],        [1] => [            //article 2        ]    ],    [2015] => [        [0] => [            //article 1        ],        [1] => [            //article 2        ]    ]]

order by 时间字段名 DESC    //时间从大到小order by 时间字段名 ASC     //时间从小到大

When you invoke the SQL statement, ORDER BY field_time Desc is not finished.

Think it should be possible to refer to a similar paging solution

is the conversion of the time type, with Strtotime.
$dated is the time stamp you took out.
Date ("Y", Strtotime ($dated)); Years
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.