PHP sorting questions

Source: Internet
Author: User
PHP sorting question this post was last edited by u010801782 at 23:32:15

 
 Demo
 
  $ Value) {array_multisort ($ sTime, SORT_ASC, $ value);?>
      
   $ V) {$ sTime [$ key] = $ v ['stime'];?>
   
$ V ['stime'] & time () <$ v ['etime']) {echo 'open Zhong';} if (time () <$ v ['stime']) {echo 'not open yet';} if (time ()> $ v ['etime']) {echo 'expired ';}?>
Expired




The final result. how can I move the expired rows to the expired rows in descending order of the time displayed on the front end.


Reply to discussion (solution)

Sort by expiration or not, and then sort by time. order by expiration, time

If only the order is arranged, the expired ones are arranged in reverse chronological order.

$ SQL = 'select * from news order by guoqi desc, time desc

If you want to classify them into different categories, you can perform two cycles. The unexpired list position loops once, and the expired list position loops once, and the fields that expire are determined directly when the content is output in a loop.

If only the order is arranged, the expired ones are arranged in reverse chronological order.

$ SQL = 'select * from news order by guoqi desc, time desc

If you want to classify them into different categories, you can perform two cycles. The unexpired list position loops once, and the expired list position loops once, and the fields that expire are determined directly when the content is output in a loop.

How can we implement the loop output in different categories? Is there an instance?

 
  $ Value) {array_multisort ($ sTime, SORT_ASC, $ value);?>
      
   $ V) {if (time () <= $ v ['etime']) {$ sTime [$ key] = $ v ['stime'];?>
   
   $ Value) {array_multisort ($ sTime, SORT_ASC, $ value);?>
       
   $ V) {if (time ()> $ v ['etime']) {$ sTime [$ key] = $ v ['stime'];?>
   
$ V ['stime'] & time () <$ v ['etime']) {echo 'open Zhong';} if (time () <$ v ['stime']) {echo 'not open yet';}?>
Expired
Expired


When you determine whether the expiration date has expired in two cycles, the others are displayed.

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.