Advertisement
Mista

Untitled

Aug 21st, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.53 KB | None | 0 0
  1. ---------------------------------------------------su-server----------------------------------------------------------
  2. <?php
  3. include"config/koneksi.php";
  4. mb_internal_encoding('UTF-8');
  5.  
  6. /**
  7. * Array of database columns which should be read and sent back to DataTables. Use a space where
  8. * you want to insert a non-database field (for example a counter or static image)
  9. */
  10. $aColumns = array( 'id','nik','nama','nopol', 'cabang'); //Kolom Pada Tabel
  11.  
  12. // Indexed column (used for fast and accurate table cardinality)
  13. $sIndexColumn = 'id';
  14.  
  15. // DB table to use
  16. $sTable = 'supir' and 'staff'; // Nama Tabel
  17.  
  18.  
  19.  
  20.  
  21. /**
  22. * Paging
  23. */
  24. $sLimit = "";
  25. if ( isset( $input['iDisplayStart'] ) && $input['iDisplayLength'] != '-1' ) {
  26. $sLimit = " LIMIT ".intval( $input['iDisplayStart'] ).", ".intval( $input['iDisplayLength'] );
  27. }
  28.  
  29.  
  30. /**
  31. * Ordering
  32. */
  33. $aOrderingRules = array();
  34. if ( isset( $input['iSortCol_0'] ) ) {
  35. $iSortingCols = intval( $input['iSortingCols'] );
  36. for ( $i=0 ; $i<$iSortingCols ; $i++ ) {
  37. if ( $input[ 'bSortable_'.intval($input['iSortCol_'.$i]) ] == 'true' ) {
  38. $aOrderingRules[] =
  39. "`".$aColumns[ intval( $input['iSortCol_'.$i] ) ]."` "
  40. .($input['sSortDir_'.$i]==='asc' ? 'asc' : 'desc');
  41. }
  42. }
  43. }
  44.  
  45. if (!empty($aOrderingRules)) {
  46. $sOrder = " ORDER BY ".implode(", ", $aOrderingRules);
  47. } else {
  48. $sOrder = "";
  49. }
  50.  
  51.  
  52. /**
  53. * Filtering
  54. * NOTE this does not match the built-in DataTables filtering which does it
  55. * word by word on any field. It's possible to do here, but concerned about efficiency
  56. * on very large tables, and MySQL's regex functionality is very limited
  57. */
  58. $iColumnCount = count($aColumns);
  59.  
  60. if ( isset($input['sSearch']) && $input['sSearch'] != "" ) {
  61. $aFilteringRules = array();
  62. for ( $i=0 ; $i<$iColumnCount ; $i++ ) {
  63. if ( isset($input['bSearchable_'.$i]) && $input['bSearchable_'.$i] == 'true' ) {
  64. $aFilteringRules[] = "`".$aColumns[$i]."` LIKE '%".$db->real_escape_string( $input['sSearch'] )."%'";
  65. }
  66. }
  67. if (!empty($aFilteringRules)) {
  68. $aFilteringRules = array('('.implode(" OR ", $aFilteringRules).')');
  69. }
  70. }
  71.  
  72. // Individual column filtering
  73. for ( $i=0 ; $i<$iColumnCount ; $i++ ) {
  74. if ( isset($input['bSearchable_'.$i]) && $input['bSearchable_'.$i] == 'true' && $input['sSearch_'.$i] != '' ) {
  75. $aFilteringRules[] = "`".$aColumns[$i]."` LIKE '%".$db->real_escape_string($input['sSearch_'.$i])."%'";
  76. }
  77. }
  78.  
  79. if (!empty($aFilteringRules)) {
  80. $sWhere = " WHERE ".implode(" AND ", $aFilteringRules);
  81. } else {
  82. $sWhere = "";
  83. }
  84.  
  85.  
  86. /**
  87. * SQL queries
  88. * Get data to display
  89. */
  90. $aQueryColumns = array();
  91. foreach ($aColumns as $col) {
  92. if ($col != ' ') {
  93. $aQueryColumns[] = $col;
  94. }
  95. }
  96.  
  97. $sQuery = "
  98. SELECT SQL_CALC_FOUND_ROWS `".implode("`, `", $aQueryColumns)."`
  99. FROM `".$sTable."`".$sWhere.$sOrder.$sLimit;
  100.  
  101. $rResult = $db->query( $sQuery ) or die($db->error);
  102.  
  103. // Data set length after filtering
  104. $sQuery = "SELECT FOUND_ROWS()";
  105. $rResultFilterTotal = $db->query( $sQuery ) or die($db->error);
  106. list($iFilteredTotal) = $rResultFilterTotal->fetch_row();
  107.  
  108. // Total data set length
  109. $sQuery = "SELECT COUNT(`".$sIndexColumn."`) FROM `".$sTable."`";
  110. $rResultTotal = $db->query( $sQuery ) or die($db->error);
  111. list($iTotal) = $rResultTotal->fetch_row();
  112.  
  113.  
  114. /**
  115. * Output
  116. */
  117.  
  118. $output = array(
  119. "sEcho" => intval($input['sEcho']),
  120. "iTotalRecords" => $iTotal,
  121. "iTotalDisplayRecords" => $iFilteredTotal,
  122. "aaData" => array(),
  123. );
  124.  
  125. // Looping Data
  126. while ( $aRow = $rResult->fetch_assoc() ) {
  127. $row = array();
  128. $btn = '<a href="#" onClick="showModals(\''.$aRow['id'].'\')">Edit</a> | <a href="#" onClick="deleteUser(\''.$aRow['id'].'\')">delete</a>';
  129. for ( $i=0 ; $i<$iColumnCount ; $i++ ) {
  130. $row[] = $aRow[ $aColumns[$i] ];
  131. }
  132. $row = array( $btn, $aRow['nik'], $aRow['nama'],$aRow['nopol'],$aRow['cabang'] );
  133. $output['aaData'][] = $row;
  134. }
  135.  
  136. echo json_encode( $output );
  137.  
  138. ?>
  139.  
  140. --------------------------------------------------------------- su-proses------------------------------------------------------
  141. <?php
  142. include"config/koneksi.php";
  143.  
  144.  
  145. switch ($_POST['type']) {
  146.  
  147. //Tampilkan Data
  148. case "get":
  149.  
  150. $SQL = mysqli_query($db, "SELECT * FROM supir,staff where staff.nik=supir.nik and supir.id='".$_POST['id']."'");
  151. $return = mysqli_fetch_array($SQL,MYSQLI_ASSOC);
  152. echo json_encode($return);
  153. break;
  154.  
  155. //Tambah Data
  156. case "new":
  157.  
  158. //serid = date("ymdhis")."_".rand(0,10);
  159. $SQL = mysqli_query($db,
  160. "INSERT INTO supir SET
  161. id=UPPER('".$_POST['id']."'),
  162. nik=UPPER('".$_POST['nik']."'),
  163. nopol=UPPER('".$_POST['nopol']."'),
  164. cabang=UPPER('".$_POST['cabang']."')
  165. ");
  166. if($SQL){
  167. echo json_encode("OK")or die("Salah Di ".mysqli_error);
  168. }
  169. break;
  170.  
  171. //Edit Data
  172. case "edit":
  173.  
  174. $SQL = mysqli_query($db,
  175. "UPDATE supir SET
  176. nik=UPPER('".$_POST['nik']."'),
  177. nopol=UPPER('".$_POST['nopol']."'),
  178. cabang=UPPER('".$_POST['cabang']."')
  179. WHERE id='".$_POST['id']."'
  180. ");
  181. if($SQL){
  182. echo json_encode("OK")or die("Salah Di ".mysqli_error);
  183. }
  184. break;
  185.  
  186. //Hapus Data
  187. case "delete":
  188.  
  189. $SQL = mysqli_query($db, "DELETE FROM supir WHERE id='".$_POST['id']."'");
  190. if($SQL){
  191. echo json_encode("OK")or die("Salah Di ".mysqli_error);
  192. }
  193. break;
  194. }
  195.  
  196. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement