2015-02-23 17 views
1

我在JQuery數據表中顯示數據庫中的數據。我想在最上面顯示最新插入的記錄。我的SQL查詢工作正常,但無論如何JQuery數據表排序不會發生.....所以我想排序數據表的數據DESC順序。我在哪裏必須改變插件?我使用了以下插件:如何在DESC中顯示jquery數據表的排序

jquery.dataTables.js,jquery.resizable.js,jquery.sortable.js

這是我的代碼:

Appointments.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> 
+1

請粘貼你試過的東西? – 2015-02-23 06:12:24

回答

1

您可以通過以下方式完成此操作。可能會幫助你。

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

你可以閱讀更多的選擇here並點擊 「fnSort」 排序的細節。

+0

謝謝你的工作...... – Arun 2015-02-23 06:44:52

相關問題