Advertisement
Guest User

SORTING

a guest
Aug 26th, 2016
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.34 KB | None | 0 0
  1. <?php
  2.     $host = 'localhost';
  3.     $user = 'root';
  4.     $pass = '4nt0n1u5';
  5.     $db = 'e-report-2016';
  6.     $koneksi = mysql_connect($host,$user,$pass) or die ('gagal koneksi');
  7.     $pilih_db = mysql_select_db($db) or die ('salah pilih database"');
  8.  
  9.     function rupiah($nilai){
  10.         $nilai_baru=number_format($nilai,0,',','.');
  11.         return $nilai_baru;
  12.     }
  13. ?>
  14.  
  15. <html>
  16.  
  17. <head>
  18.     <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css">
  19. </head>
  20.  
  21. <body>
  22.  
  23. <table id="example" class="display" cellspacing="0" width="100%">
  24.         <thead>
  25.             <tr>
  26.                 <th>No. Trans</th>
  27.                 <th>Kode Rekening</th>
  28.                 <th>Jumlah</th>
  29.             </tr>
  30.         </thead>
  31.         <tfoot>
  32.             <tr>
  33.                 <th>No. Trans</th>
  34.                 <th>Kode Rekening</th>
  35.                 <th>Jumlah</th>
  36.             </tr>
  37.         </tfoot>
  38.         <tbody>
  39.         <?php
  40.             $sql="select no_trans,kode_rekening,jumlah from pengeluaran where jumlah > 1000000
  41.                    order by no_trans desc limit 1 ,25";
  42.         $query=mysql_query($sql) or die (mysql_error());
  43.         while($data=mysql_fetch_assoc($query)){
  44.         ?>
  45.             <tr>
  46.                 <td><?php echo $data['no_trans']; ?></td>
  47.                 <td><?php echo $data['kode_rekening']; ?></td>
  48.                 <td><?php echo rupiah($data['jumlah']); ?></td>
  49.             </tr>
  50.         <?php } ?>
  51.         </tbody>
  52.     </table>
  53.  
  54.     <script src="https://code.jquery.com/jquery-1.12.3.js"></script>
  55.     <script src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>
  56.     <script>
  57.         jQuery.extend( jQuery.fn.dataTableExt.oSort, {
  58.             "my-currency-pre": function(a) {
  59.                 return parseFloat(a.replace(/ /gi, ''));
  60.             },
  61.             "my-currency-asc": function(a,b) {
  62.                 return ((a < b) ? -1 : ((a > b) ? 1 : 0));
  63.             },
  64.             "my-currency-desc": function(a,b) {
  65.                 return ((a < b) ? 1 : ((a > b) ? -1 : 0));
  66.             }
  67.         });
  68.  
  69.         var table = $('#example').dataTable({
  70.            "aoColumnDefs": [
  71.               {"sType": "my-currency", "aTargets": [2]}
  72.            ],
  73.            "order": [[ 2, 'asc' ],]
  74.         });  
  75.     </script>
  76. </body>
  77. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement