PHP mysql order by未按预期工作

PHP mysql order by未按预期工作,mysql,sql-order-by,Mysql,Sql Order By,我试图在HTLM css(used bootstrap)选项卡中显示mysql数据库中的数据。但查询结果未按预期的“ID”顺序显示。有人能帮我解决我的问题吗? 提前谢谢 <table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered" id="example"> <div class="alert alert-info"> <

我试图在HTLM css(used bootstrap)选项卡中显示mysql数据库中的数据。但查询结果未按预期的“ID”顺序显示。有人能帮我解决我的问题吗? 提前谢谢

<table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered" id="example">
    <div class="alert alert-info">
        <strong><center>Delete Multiple Data:Check the Box and click the Delete button to Delete Data </strong></center>
    </div>
    <thead>
        <tr>
            <th>#</th>
            <th>ID</th>
            <th>Value Date</th>
            <th>Type</th>
            <th>Amount</th>
            <th>Donated By</th>
            <th>Paid To</th>
        </tr>
    </thead>
    <tbody>
        <?php
            $query=mysql_query("select * from temple_txn order by id desc")or die(mysql_error());
            while($row=mysql_fetch_array($query)){
                $id=$row['id'];
                ?>
                <tr>
                    <td><input name="selector[]" type="checkbox" value="<?php echo $id; ?>"></td>
                    <td><?php echo $row['id'] ?></td>
                    <td><?php echo $row['value_date'] ?></td>
                    <td><?php echo $row['txn_type'] ?></td>
                    <td><?php echo $row['txn_amount'] ?></td>
                    <td><?php echo $row['donated_by'] ?></td>
                    <td><?php echo $row['paid_to'] ?></td>
                </tr>
        <?php } ?>
    </tbody>
</table>

删除多个数据:选中该框并单击删除按钮删除数据
#
身份证件
起息日
类型
数量
捐赠人
支付给
(JS DT_引导)

/*设置数据表初始化的默认值*/
$.extend(true,$.fn.dataTable.defaults{
“sDom”:“t”,
“sPaginationType”:“引导程序”,
“语言”:{
“sLengthMenu”:“\u MENU\u每页记录”
}
} );
/*默认类修改*/
$.extend($.fn.dataTableExt.ostdclass{
“sWrapper”:“dataTables\u包装表单内联”
} );
/*获取分页信息的API方法*/
$.fn.dataTableExt.oApi.fnPagingInfo=函数(oSettings)
{
返回{
“iStart”:oSettings._i显示开始,
“iEnd”:oSettings.fnDisplayEnd(),
“i长度”:o设置。i显示长度,
“iTotal”:oSettings.fnRecordsTotal(),
“iFilteredTotal”:oSettings.fnRecordsDisplay(),
“iPage”:oSettings._i显示长度==-1?
0:Math.ceil(oSettings.\u iDisplayStart/oSettings.\u iDisplayLength),
“iTotalPages”:oSettings._i显示长度==-1?
0:Math.ceil(oSettings.fnRecordsDisplay()/oSettings.\u iDisplayLength)
};
};
/*引导式分页控件*/
$.extend($.fn.dataTableExt.oPagination{
“引导”:{
“fnInit”:函数(oSettings、nPaging、fnDraw){
var oLang=oSettings.olalanguage.oPaginate;
var fnClickHandler=函数(e){
e、 预防默认值();
if(oSettings.oApi.\u fnPageChange(oSettings,e.data.action)){
fnDraw(oSettings);
}
};
$(nPaging).addClass('pagination').append(
“
    ”+ “
  • ”+ “
  • ”+ “
” ); 变量els=$('a',nPaging); $(els[0]).bind('click.DT',{action:'previous},fnClickHandler); $(els[1]).bind('click.DT',{action:'next},fnClickHandler); }, “FNDUpdate”:功能(oSettings,fnDraw){ 可变长度=5; var oPaging=oSettings.oInstance.fnPagingInfo(); var an=oSettings.aanFeatures.p; 变量i、ien、j、sClass、iStart、iEnd、iHalf=数学楼层(iListLength/2); if(oPaging.iTotalPages对于(i=0,ien=an.length;i似乎您从数据库中以正确的顺序获取数据。根据我们在问题注释中的对话,我认为您的问题是由JS库或pageload后的引导插件引起的。为了确保这一点,请停用JavaScript,并查看行的顺序是否正确(如果不正确)被插件感动了

如果DataTables尝试按第一列中的值进行排序(其中有一些
HTML
),这可能解释了看似随机的排序。请尝试设置隐式顺序/排序设置()。您的ID位于第二列,列索引是零基的,因此这就是:

$(document).ready(function() {
    $('#example').dataTable( {
        "sPaginationType": "bootstrap",
        "oLanguage": {},
        "aaSorting": [[1,'desc']]
    });
});

您得到的输出是什么?顺便说一句:不要使用
作为
的直接子级,请参阅
的内容模型:。我得到的是表格数据,但正如我所说的,它没有按顺序显示(不是在desc或asc中)。它应该可以工作™. 这些行是按特定顺序排列还是完全随机?您是否使用了一些JavaScript datagrid/table插件,可能会在pageload后洗牌这些行?是的,它的Complete random.JS用于引导(默认情况下),没有其他功能。此外,我对JS不熟悉。是的,JS“DT_引导”(默认情况下用于引导css)正在制造问题…有人能帮忙处理吗?我不熟悉JS。如果需要,我可以分享JS。非常感谢…工作正常…如预期。再次感谢支持。
$(document).ready(function() {
    $('#example').dataTable( {
        "sPaginationType": "bootstrap",
        "oLanguage": {},
        "aaSorting": [[1,'desc']]
    });
});