dtcmadj31951 2014-01-19 16:59
浏览 97
已采纳

使用foreach时按日期排序

I am creating a page to list select columns from each row in a table. I have the basics of that down by using a foreach loop as below and it works fine. The problem I am up against now is that I need to order the results by date (one of the columns) with the newest record being at the top.

This is what I have so far (that works but without sorting)

foreach ($visitors as $visitor) {
        $id = htmlentities($visitor['family_id']);
        $first_name = htmlentities($visitor['first_name']);
        $last_name = htmlentities($visitor['last_name']);
        $visit_date = htmlentities($visitor['visit_date']);
        $phone = htmlentities($visitor['phone']);
        $email = htmlentities($visitor['email']);
        ?>

        <p><?php echo $visit_date; ?><a href="visitor-view.php?id=<?php echo $id; ?>"> <?php echo $first_name . ' ' . $last_name; ?></a> <?php echo $phone; echo $email; ?></p>
        <?php
    } 

Hoping someone has a bright idea as to how to get it to sort.

  • 写回答

2条回答 默认 最新

  • dqnz43863 2014-01-19 17:20
    关注

    Stupid oversight from myself, trying to make it more complicated that it should have been.

    Using suggestion from Dragon Warrior was by far the simplest way to do it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?