如何在DESC中显示jquery数据表的排序



我正在JQuery数据表中显示数据库中的数据。我想在顶部显示最新插入的记录。我的SQL查询运行良好,但JQuery数据表排序没有发生。。。。。所以我想对数据表的数据DESC顺序进行排序。我必须在哪里更改插件?我正在使用以下插件:

jquery.dataTables.js、jquery.resizable.js、jquery.sortal.js

这是我的代码:

预约.php

            <head>
            <!--<meta http-equiv="refresh" content="30" />
            --></head>
            <?php
                include_once 'config.php';
                $menu_name = 'patient'; 
                $_SESSION['menu']= $menu_name;  
                if(isset($_REQUEST['id']) && $_REQUEST['id']!='')
                {
                    if(isset($_REQUEST['act']) && $_REQUEST['act']!='')
                    {
                        if($_REQUEST['act']=='r')
                        {
                            $id = $_REQUEST['id'];
                            $deleteCondition = " id_patient='".$id."'";
                            $deleted=$db->delete('patients',$deleteCondition);
                            header("Location: appointments.php?m=r");
                        }
                    }
                }
               /*echo $query="SELECT p.*,u.fileno FROM patients AS p,users AS u WHERE p.status='a' AND p.users_id_user=u.id_user order by p.id_patient DESC";*/
              /*echo  $query="select p.*,u.fileno,s.title from patients as p INNER JOIN users as u ON p.users_id_user=u.id_user
               left join services as s ON p.service_id=s.id_service where p.status='a'"; */
                echo  $query="select p.*,u.fileno,s.title from patients as p INNER JOIN users as u ON p.users_id_user=u.id_user
               left join photos as s ON p.service_id=s.id_photo where p.status='a' order by p.id_patient DESC";
               $resultPatient=$db->select($query);

               //$qry="select p.*,s.title from patients as p,service as s innser join services on p.service_id=s.id_service";
                //$resultPatient=$db->select($qry);
                $msgConfirmDelete ="Do you really want to delete this Patient ?";
                include_once 'header.php';
            ?>
            <script type="text/javascript">
             var msgDelete = '<?php echo $msgConfirmDelete; ?>';
             function confirmDelete()
             {
             if (confirm(msgDelete))
             {
             return true;
             }
             else
             {
             return false;
             }
             }
             </script> 
            <!-- Sidebar begins -->
            <div id="sidebar">
                <!-- Left Main menu begins -->
                    <?php include_once 'menu.php'; ?>
                <!-- Left Main menu ends -->

                <!-- Secondary nav --> 
                <div class="secNav">
                    <div class="secWrapper">
                        <!--div class="secTop">
                        </div-->
                        <!--div class="divider"></div-->
                        <div id="general">
                            <div id="general" style="display: block;" class="active">
                            <ul class="subNav">
                                <li><a href="add_appointment.php" title=""><span class="icos-images2"></span>Add Appointment</a></li>
                                <li class="activeli"><a href="appointments.php" title="" class="this"><span class="icos-images2"></span>View/Edit Appointments</a></li>
                                <li><a href="appointments_history.php" title=""><span class="icos-images2"></span>Appointments History</a></li>
                                <li><a href="reminder_settings.php" title=""><span class="icos-images2"></span>View/Edit Reminder Settings</a></li>
                                <li><a href="add_reminder_settings.php" title=""><span class="icos-images2"></span>Add Reminder Settings</a></li>
                                <li><a href="medicine_reminder_settings.php" title=""><span class="icos-images2"></span>View/Edit Medicine Reminder Settings</a></li>
                                <li><a href="add_medicine_reminder_settings.php" title=""><span class="icos-images2"></span>Add Medicine Reminder Settings</a></li>
                            </ul>
                        </div>   
                        </div> 
                   </div> 
                   <div class="clear"></div>
               </div>
            </div>
            <!-- Sidebar ends -->

            <!-- Content begins -->
            <div id="content">
                <div class="contentTop">
                    <span class="pageTitle"><span class="icon-screen"></span>View Appointments</span>
                    <div class="clear"></div>
                </div>
                <!-- Breadcrumbs line -->
                <div class="breadLine">
                    <div class="bc">
                        <ul id="breadcrumbs" class="breadcrumbs">
                            <li><a href="index.php">Dashboard</a></li>
                            <li><a href="appointments.php">Appointments</a></li>
                            <li class="current"><a href="#" title="">View Appointments</a></li>
                        </ul>
                    </div>
                </div>
                <!-- Main content -->
                <div class="wrapper">

                    <div class="fluid">
                        <?php if(isset($_GET['m'])&&$_GET['m']=="a"){?>
                       <div class="nNote nSuccess">
                      <p>Appointment Added Successfully !</p>
                      </div>
                       <?php  }
                       if(isset($_GET['m'])&&$_GET['m']=="d"){?>
                       <div class="nNote nSuccess">
                      <p>Appointment Status Changed Successfully !</p>
                      </div>
                      <?php  }
                       if(isset($_GET['m'])&&$_GET['m']=="r"){?>
                       <div class="nNote nSuccess">
                      <p>Appointment Deleted Successfully !</p>
                      </div>
                      <?php  }
                       if(isset($_GET['m'])&&$_GET['m']=="re"){?>
                       <div class="nNote nSuccess">
                      <p>Reminder Sent Successfully !</p>
                      </div>
                      <?php } 
                       if(isset($_GET['m'])&&$_GET['m']=="u"){?>
                       <div class="nNote nSuccess">
                      <p>Appointment Updated Successfully !</p>
                      </div>
                      <?php } ?>
                    <div class="widget">
                        <div class="whead"><h6>View Appointment Information</h6><div class="clear"></div></div>
                        <div id="dyn2" class="shownpars">
                            <a class="tOptions act" title="Options"><img src="images/icons/options.png" alt="" /></a>
                            <table cellpadding="0" cellspacing="0" border="0" class="dTable">
                            <thead>
                            <tr>
                            <th>Sl. No.<span class="sorting" style="display: block;"></span></th>
                            <!--<th>Sl.No</th>-->
                            <th>Date</th>
                            <th>File No</th>
                            <th>Name</th>
                            <th>Email</th>
                            <th>Age</th>
                            <th>Gender</th>
                            <th>Service</th>
                            <th>Phone</th>
                            <th>Time</th>
                            <th width="80">Action</th>
                            </tr>
                            </thead>
                            <tbody>
                            <?php
                            $sl=0;
                            $req_date='';   
                            if($resultPatient && count($resultPatient)>0)
                            foreach($resultPatient as $patient)
                            {
                                $sl+=1;                    
                                $req_date=date('d F Y', strtotime($patient['date']));
                            ?>
                                <tr class="gradeX">
                                <td class="center"><?php echo $sl;?></td>
                                <td class="center"><?php echo $req_date;?></td>
                                <td class="center"><?php echo $patient['fileno'];?></td>
                                <td class="center"><?php echo $patient['name'];?></td>
                                <td class="center"><?php echo $patient['email'];?></td>
                                <td class="center"><?php echo $patient['age'];?></td>
                                <td class="center"><?php echo strtoupper($patient['gender']);?></td>
                                <td class="center"><?php echo $patient['title'];?></td>
                                <td class="center"><?php echo $patient['phone'];?></td>
                                <td class="center"><?php echo $patient['time'];?></td>
                                <td class="tableActs">
                                <a href="edit_appointment.php?id=<?php echo $patient['id_patient'];?>" class="tablectrl_small <?php if($patient['confirm_status']=='c') echo 'bGreen'; else echo 'bDefault';?> tipS" title="Edit"><span class="iconb" data-icon="&#xe1db;"></span></a>
                                <a onclick="return confirmDelete();" href="appointments.php?id=<?php echo $patient['id_patient'];?>&act=r" class="tablectrl_small bDefault tipS" title="Delete"><span class="iconb" data-icon="&#xe136;"></span></a>
                                <a href="solveAppointments.php?id=<?php echo $patient['id_patient'];?>" class="lightbox tablectrl_small bDefault tipS" title="Status"><span class="iconb" data-icon="&#xe047;"></span></a>
                                </td>
                                </tr>
                                <?php }?>                
                            </tbody>
                            </table> 
                        </div>
                        <div class="clear"></div> 
                    </div> 
                    </div>
                </div>
                <!-- Main content ends -->
            </div>
            <!-- Content ends -->
            </body>
            </html>

您可以通过以下方式完成此操作。也许它对你有帮助。

 $(document).ready(function() {  var oTable = $('#example').dataTable(); oTable.fnSort( [ [0,'asc'], [1,'asc'] ] );} );

您可以在此处阅读更多选项,并单击"fnSort"了解排序详细信息。

最新更新