我将php表单用于sql数据视图。问题是我想查看顶部的最新数据和最后的旧数据。可以帮我吗? 这是我的php表单查看代码。 这里的所有详细信息用于从sql获取数据。和它的工作正常,但需要从新到旧查看。
<table cellpadding="0" cellspacing="0" border="0" class="datatable table table-striped table-bordered">
<thead>
<tr>
<th>S.No</th>
<th class="wraper-title">Notice Title</th>
<th>Publish Date</th>
<th>Type</th>
<th>View</th>
<th>Delete</th>
<th>Download</th>
</tr>
</thead>
<tbody>
<?php
while($r = mysqli_fetch_assoc($result)){
?>
<tr>
<th scope="row"><?php echo $r['id'] ?></th>
<td class="wraper-title"><?php echo $r['name'] ?></td>
<td><?php echo $r['date'] ?></td>
<td><?php echo $r['type'] ?></td>
<td>
<a type="button" class="btn btn-success" href="<?php echo $r['location'] ?>">View</a>
</td>
<td>
<a type="button" class="btn btn-danger delete" title="Delete this notice" href="#" onclick='DeleteFile(<?php echo $r['id'] ?>)'><i class="glyphicon glyphicon-trash"></i></a>
</td>
<td>
<a type="button" class="btn btn-primary download" href="<?php echo $r['location'] ?>" title="Download <?php echo $r['name'] ?>" download="<?php echo $r['name'] ?>" {%=file.thumbnailUrl?'data-gallery':''%}><i class="glyphicon glyphicon-download"></i></a>
</td>
</tr>
<?php
}
?>
</tbody>
<tfoot>
<tr>
<th>S.No</th>
<th class="wraper-title">Notice Title</th>
<th>Publish Date</th>
<th>Type</th>
<th>View</th>
<th>Delete</th>
<th>Download</th>
</tr>
</tfoot>
</table>
请帮助我
答案 0 :(得分:0)
您可以尝试使用此功能。这将按升序对第一和第二列进行排序。
其中0和1是列的索引
$('#table_id').dataTable( {
"order": [[ 0, 'asc' ], [ 1, 'asc' ]]
});