大家好, 我想按日期排序我的表,但我无法对其进行排序。 希望你们能帮助我。
这是我的代码
<table class="table table-striped table-bordered bootstrap-datatable datatable responsive">
<thead>
<tr>
<th>Name</th>
<th>Action</th>
<th>Date and Time</th>
</tr>
</thead>
<tbody>
<?php
$result= mysql_query("select * from history order by history_id DESC ") or die (mysql_error());
while ($row= mysql_fetch_array ($result) ){
$id=$row['history_id'];
?>
<tr>
<td><?php echo $row['data']; ?></td>
<td><span class="label-primary label label-default"><?php echo $row['action']; ?></span></td>
<td><span class="label-success label label-default"><?php echo date("M d, Y H:i:s",strtotime($row['date'])); ?></span></td>
</tr>
<?php } ?>
</tbody>
</table>
答案 0 :(得分:1)
您忘记粘贴代码,因此我希望这是您想要的:
按日期排序表,降序:
ALTER TABLE table1
ORDER BY table1.Date DESC,
按日期按升序排序:
ALTER TABLE table1
ORDER BY table1.Date ASC