简体   繁体   中英

Reorder database result

I need the results to show the most recent first - at the moment this code shows the updates in chronological order. Unfortunately I don't have access to the query in the below code so I need to run this within the code shown. Any ideas?

<?php
    if($updates)
    {
        foreach($updates as $up)
        {
?>
<li class="common_li" style="background:none; border:none; padding:0px;"> 

<p style="font-size:12px; font-weight:nornal; font-style:italic;  color:#999999;"> 

<?php echo date($site_setting['date_format'],strtotime($up['date_added'])); ?></p>

<div style="border-radius:8px 8px 8px 8px;" class="detail_update">

<?php echo $up['updates'] ; ?></div>
</li>
?>

You need to find out where the $updates variable is coming from and change the query there.

Another option is to sort the variable by the date_added key:

function sort_by_date( $a, $b ) {
   return strtotime( $a[ 'date_added' ] ) - strtotime( $b[ 'date_added' ] );
}

usort( $updates, "sort_by_date" );

Changing the query is the cleaner way, so I recommend doing that if at all possible.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM