Advertisement
deprie2324

serverside

Sep 1st, 2015
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.85 KB | None | 0 0
  1. <?php
  2.     /**
  3.         * Script:    DataTables server-side script for PHP 5.2+ and MySQL 4.1+
  4.         * Notes:     Based on a script by Allan Jardine that used the old PHP mysql_* functions.
  5.         *            Rewritten to use the newer object oriented mysqli extension.
  6.         * Copyright: 2010 - Allan Jardine (original script)
  7.         *            2012 - Kari Söderholm, aka Haprog (updates)
  8.         * License:   GPL v2 or BSD (3-point)
  9.     */
  10.     mb_internal_encoding('UTF-8');
  11.    
  12.     /**
  13.         * Array of database columns which should be read and sent back to DataTables. Use a space where
  14.         * you want to insert a non-database field (for example a counter or static image)
  15.     */
  16.     $aColumns = array( 'id_deposit', 'tanggal', 'kode','nama_maskapai','nilai','nama_rek','keterangan' ); //Kolom Pada Tabel
  17.    
  18.     // Indexed column (used for fast and accurate table cardinality)
  19.     $sIndexColumn = 'id_deposit';
  20.    
  21.     // DB table to use
  22.     $sTable = 'tb_deposit_maskapai'; // Nama Tabel
  23.    
  24.     // Database connection information
  25.     $gaSql['user']     = 'root';
  26.     $gaSql['password'] = '';  
  27.     $gaSql['db']       = 'tes';  //Database
  28.     $gaSql['server']   = 'localhost';  
  29.     $gaSql['port']     = 3306; // 3306 is the default MySQL port
  30.    
  31.     // Input method (use $_GET, $_POST or $_REQUEST)
  32.     $input =& $_POST;
  33.  
  34.     $gaSql['charset']  = 'utf8';
  35.    
  36.     /**
  37.         * MySQL connection
  38.     */
  39.     $db = new mysqli($gaSql['server'], $gaSql['user'], $gaSql['password'], $gaSql['db'], $gaSql['port']);
  40.     if (mysqli_connect_error()) {
  41.         die( 'Error connecting to MySQL server (' . mysqli_connect_errno() .') '. mysqli_connect_error() );
  42.     }
  43.    
  44.     if (!$db->set_charset($gaSql['charset'])) {
  45.         die( 'Error loading character set "'.$gaSql['charset'].'": '.$db->error );
  46.     }
  47.    
  48.    
  49.     /**
  50.         * Paging
  51.     */
  52.     $sLimit = "";
  53.     if ( isset( $input['iDisplayStart'] ) && $input['iDisplayLength'] != '-1' ) {
  54.         $sLimit = " LIMIT ".intval( $input['iDisplayStart'] ).", ".intval( $input['iDisplayLength'] );
  55.     }
  56.    
  57.    
  58.     /**
  59.         * Ordering
  60.     */
  61.     $aOrderingRules = array();
  62.     if ( isset( $input['iSortCol_0'] ) ) {
  63.         $iSortingCols = intval( $input['iSortingCols'] );
  64.         for ( $i=0 ; $i<$iSortingCols ; $i++ ) {
  65.             if ( $input[ 'bSortable_'.intval($input['iSortCol_'.$i]) ] == 'true' ) {
  66.                 $aOrderingRules[] =
  67.                 "`".$aColumns[ intval( $input['iSortCol_'.$i] ) ]."` "
  68.                 .($input['sSortDir_'.$i]==='asc' ? 'asc' : 'desc');
  69.             }
  70.         }
  71.     }
  72.    
  73.     if (!empty($aOrderingRules)) {
  74.         $sOrder = " ORDER BY ".implode(", ", $aOrderingRules);
  75.         } else {
  76.         $sOrder = " ";
  77.     }
  78.    
  79.    
  80.     /**
  81.         * Filtering
  82.         * NOTE this does not match the built-in DataTables filtering which does it
  83.         * word by word on any field. It's possible to do here, but concerned about efficiency
  84.         * on very large tables, and MySQL's regex functionality is very limited
  85.     */
  86.     $iColumnCount = count($aColumns);
  87.    
  88.     if ( isset($input['sSearch']) && $input['sSearch'] != "" ) {
  89.         $aFilteringRules = array();
  90.         for ( $i=0 ; $i<$iColumnCount ; $i++ ) {
  91.             if ( isset($input['bSearchable_'.$i]) && $input['bSearchable_'.$i] == 'true' ) {
  92.                 $aFilteringRules[] = "`".$aColumns[$i]."` LIKE '%".$db->real_escape_string( $input['sSearch'] )."%'";
  93.             }
  94.         }
  95.         if (!empty($aFilteringRules)) {
  96.             $aFilteringRules = array('('.implode(" OR ", $aFilteringRules).')');
  97.         }
  98.     }
  99.    
  100.     // Individual column filtering
  101.     for ( $i=0 ; $i<$iColumnCount ; $i++ ) {
  102.         if ( isset($input['bSearchable_'.$i]) && $input['bSearchable_'.$i] == 'true' && $input['sSearch_'.$i] != '' ) {
  103.             $aFilteringRules[] = "`".$aColumns[$i]."` LIKE '%".$db->real_escape_string($input['sSearch_'.$i])."%'";
  104.         }
  105.     }
  106.    
  107.     if (!empty($aFilteringRules)) {
  108.         $sWhere = " WHERE ".implode(" AND ", $aFilteringRules);
  109.         } else {
  110.         $sWhere = "";
  111.     }
  112.    
  113.     /* Join Tabel   */
  114.     $sJoin = " left join tb_maskapai on tb_deposit_maskapai.id_maskapai = tb_maskapai.id_maskapai
  115.                left join tb_rek on tb_deposit_maskapai.id_rek=tb_rek.id_rek";
  116.     /*-------------------------*/
  117.    
  118.     $aksi="module/mod_deposit_maskapai/proses.php";
  119.    
  120.     /**
  121.         * SQL queries
  122.         * Get data to display
  123.     */
  124.     $aQueryColumns = array();
  125.     foreach ($aColumns as $col) {
  126.         if ($col != ' ') {
  127.             $aQueryColumns[] = $col;
  128.         }
  129.     }
  130.    
  131.  
  132.     $sQuery = "
  133.    SELECT SQL_CALC_FOUND_ROWS `".implode("`, `", $aQueryColumns)."`
  134.    FROM `".$sTable."`".$sJoin.$sWhere.$sOrder.$sLimit;
  135.    
  136.     $rResult = $db->query( $sQuery ) or die($db->error);
  137.    
  138.     // Data set length after filtering
  139.     $sQuery = "SELECT FOUND_ROWS()";
  140.     $rResultFilterTotal = $db->query( $sQuery ) or die($db->error);
  141.     list($iFilteredTotal) = $rResultFilterTotal->fetch_row();
  142.    
  143.     // Total data set length
  144.     $sQuery = "SELECT COUNT(`".$sIndexColumn."`) FROM `".$sTable."`";
  145.     $rResultTotal = $db->query( $sQuery ) or die($db->error);
  146.     list($iTotal) = $rResultTotal->fetch_row();
  147.    
  148.     // Fungsi rupiah //
  149.     function fungsi_rupiah($angka){
  150.       $rupiah=number_format($angka,2,',','.');
  151.       return $rupiah;
  152.     };
  153.    
  154.     /**
  155.         * Output
  156.     */
  157.     $output = array(
  158.     "sEcho"                => intval($input['sEcho']),
  159.     "iTotalRecords"        => $iTotal,
  160.     "iTotalDisplayRecords" => $iFilteredTotal,
  161.     "aaData"               => array(),
  162.     );
  163.    
  164.     // Looping Data
  165.     while ( $aRow = $rResult->fetch_assoc() ) {
  166.         $row = array();
  167.         $btn =  '<a href="?content=deposit-maskapai&act=edit&id='.$aRow['id_deposit'].'">Edit</a> | <a href="'.$aksi.'?content=deposit-maskapai&act=hapus&id='.$aRow['id_deposit'].'&kode='.$aRow['kode'].'">Hapus</a>';
  168.         for ( $i=0 ; $i<$iColumnCount ; $i++ ) {
  169.             $row[] = $aRow[ $aColumns[$i] ];
  170.         }
  171.         $row = array( '<div align="center">'.$aRow['tanggal'].'</div>', '<div align="center">'.$aRow['kode'].'</div>', '<div align="center">'.$aRow['nama_maskapai'].'</div>',
  172.                 '<div align="left" style="float:left; width:30px">Rp</div><div align="right">'.fungsi_rupiah($aRow['nilai']).'</div>', $aRow['nama_rek'], $aRow['keterangan'], '<div align="center">'.$btn.'</div>' );
  173.         $output['aaData'][] = $row;
  174.     }
  175.    
  176.     echo json_encode( $output );
  177.    
  178. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement