按日期排序事件日历,然后按时间排序

时间:2015-04-22 20:20:42

标签: php sorting date time

这是我的代码。它是按日期排序的事件的日历页面。我需要按照日期和时间对它们进行排序。 Date字段和Time字段是我需要格式化的。

<?php do { ?>

    <span class="date"><?php echo date('l, F jS',strtotime($row_rsEvents['date'])); ?><?php if(strtotime($row_rsEvents['date']) != strtotime($row_rsEvents['end_date'])) { ?> - <?php echo date('l, F jS',strtotime($row_rsEvents['end_date'])); ?><?php } ?></span><br>
    <?php if($row_rsEvents['time'] != "") { ?><span class="time"><?php echo $row_rsEvents['time']; ?></span><br><?php } ?>
    <span class="title"><?php echo $row_rsEvents['name']; ?></span><br>
            <span class="location"><?php echo $row_rsEvents['location']; ?></span><br>
    <span class="eventDescription"><?php echo $row_rsEvents['description']; ?></span><br>
    <?php if($row_rsEvents['weblink'] != "") { ?>
        <span class="webAddress"><a href="http://<?php echo $row_rsEvents['weblink']; ?>" target="_blank"><?php echo $row_rsEvents['weblink']; ?></a></span><br>
<?php } ?>
<?php if($row_rsEvents['phone'] != "") { ?><span class="webAddress"><?php echo $row_rsEvents['phone']; ?></a></span><br><?php } ?>
<?php if($row_rsEvents['email'] != "") { ?><span class="webAddress"><?php echo $row_rsEvents['email']; ?></a></span><br><?php } ?>

<?php } while ($row_rsEvents = mysql_fetch_assoc($rsEvents)); ?>

这是查询:

SELECT * FROM events WHERE 
(
    (
        DATE_FORMAT(sort_date, '%Y-%m-%d') >= Date_Format(Now(), '%Y-%m-%d') 
        OR DATE_FORMAT(end_date, '%Y-%m-%d') >= Date_Format(Now(), '%Y-%m-%d')
    ) OR (
        DATE_FORMAT(sort_date, '%Y-%m-%d') >= Date_Format(Now(), '%Y-%m-%d') 
        AND DATE_FORMAT(sort_date, '%Y-%m-%d') = DATE_FORMAT(end_date, '%Y-%m-%d')
    )
) AND authorize = 1 
ORDER BY sort_date ASC

0 个答案:

没有答案