Find a PHP code for displaying the content list based on the date line-php Tutorial

Source: Internet
Author: User
Calculate the PHP code for displaying the content list based on the date. This post was last edited by ikaimi from 2014-12-3017: 03: 46 & lt ;? Php & nbsp; $ SQL & nbsp; mysql_query (select & nbsp; title, times & nbsp; from & nbsp; table calculates a piece of PHP code that displays the content list based on the delimiter of the date.

This post was last edited by ikaimi at 17:03:46


$ SQL = mysql_query ("select title, times from table order by times desc limit 0, 50 ");
While ($ row = mysql_fetch_array ($ SQL )){
// Display only once for each date
Echo "". $ row ['Times ']. "";
// All content released on this date
Echo"
  • ". $ Row ['title']."
  • ";
    }
    ?>


    The display method is as follows:
    12-30
    Content 1 published on 12-30
    12-30 release content 2
    Content released from 12 to 30 3
    Content released from 12 to 30 4
    12-30 release content 5
    12-29
    Content 1 published on 12-29
    12-29 released content 2
    Content released on 12-29 3
    Content released on 12-29 4
    12-29 released content 5
    12-28
    Content 1 published on 12-29
    12-29 released content 2
    Content released on 12-29 3
    Content released on 12-29 4
    12-29 released content 5
    ------ Solution ----------------------

    $ SQL = mysql_query ("select title, times from table order by times desc limit 0, 50 ");
    $ Init_time = "";
    While ($ row = mysql_fetch_array ($ SQL )){
    If ($ init_time = '') {// The first cycle shows the time and the first information class.
    $ Init_time = $ row ['Times '];
    Echo "". $ row ['Times ']. "";
    Echo"
  • ". $ Row ['title']."
  • ";
    } Else {// not the first to judge whether the time is equal to the previous one
    If ($ init_time = $ row ['Times ']) {// if they are equal, the content is printed directly within the same period of time.
    Echo "". $ row ['title']. "";
    } Else {// different printing time and content
    Echo "". $ row ['Times ']. "";
    // All content released on this date
    Echo"
  • ". $ Row ['title']."
  • ";
    }
    }
    }
    ?>

    Based on your code, you can try it.

    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.