Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---------------------------------------------------su-server----------------------------------------------------------
- <?php
- include"config/koneksi.php";
- mb_internal_encoding('UTF-8');
- /**
- * Array of database columns which should be read and sent back to DataTables. Use a space where
- * you want to insert a non-database field (for example a counter or static image)
- */
- $aColumns = array( 'id','nik','nama','nopol', 'cabang'); //Kolom Pada Tabel
- // Indexed column (used for fast and accurate table cardinality)
- $sIndexColumn = 'id';
- // DB table to use
- $sTable = 'supir' and 'staff'; // Nama Tabel
- /**
- * Paging
- */
- $sLimit = "";
- if ( isset( $input['iDisplayStart'] ) && $input['iDisplayLength'] != '-1' ) {
- $sLimit = " LIMIT ".intval( $input['iDisplayStart'] ).", ".intval( $input['iDisplayLength'] );
- }
- /**
- * Ordering
- */
- $aOrderingRules = array();
- if ( isset( $input['iSortCol_0'] ) ) {
- $iSortingCols = intval( $input['iSortingCols'] );
- for ( $i=0 ; $i<$iSortingCols ; $i++ ) {
- if ( $input[ 'bSortable_'.intval($input['iSortCol_'.$i]) ] == 'true' ) {
- $aOrderingRules[] =
- "`".$aColumns[ intval( $input['iSortCol_'.$i] ) ]."` "
- .($input['sSortDir_'.$i]==='asc' ? 'asc' : 'desc');
- }
- }
- }
- if (!empty($aOrderingRules)) {
- $sOrder = " ORDER BY ".implode(", ", $aOrderingRules);
- } else {
- $sOrder = "";
- }
- /**
- * Filtering
- * NOTE this does not match the built-in DataTables filtering which does it
- * word by word on any field. It's possible to do here, but concerned about efficiency
- * on very large tables, and MySQL's regex functionality is very limited
- */
- $iColumnCount = count($aColumns);
- if ( isset($input['sSearch']) && $input['sSearch'] != "" ) {
- $aFilteringRules = array();
- for ( $i=0 ; $i<$iColumnCount ; $i++ ) {
- if ( isset($input['bSearchable_'.$i]) && $input['bSearchable_'.$i] == 'true' ) {
- $aFilteringRules[] = "`".$aColumns[$i]."` LIKE '%".$db->real_escape_string( $input['sSearch'] )."%'";
- }
- }
- if (!empty($aFilteringRules)) {
- $aFilteringRules = array('('.implode(" OR ", $aFilteringRules).')');
- }
- }
- // Individual column filtering
- for ( $i=0 ; $i<$iColumnCount ; $i++ ) {
- if ( isset($input['bSearchable_'.$i]) && $input['bSearchable_'.$i] == 'true' && $input['sSearch_'.$i] != '' ) {
- $aFilteringRules[] = "`".$aColumns[$i]."` LIKE '%".$db->real_escape_string($input['sSearch_'.$i])."%'";
- }
- }
- if (!empty($aFilteringRules)) {
- $sWhere = " WHERE ".implode(" AND ", $aFilteringRules);
- } else {
- $sWhere = "";
- }
- /**
- * SQL queries
- * Get data to display
- */
- $aQueryColumns = array();
- foreach ($aColumns as $col) {
- if ($col != ' ') {
- $aQueryColumns[] = $col;
- }
- }
- $sQuery = "
- SELECT SQL_CALC_FOUND_ROWS `".implode("`, `", $aQueryColumns)."`
- FROM `".$sTable."`".$sWhere.$sOrder.$sLimit;
- $rResult = $db->query( $sQuery ) or die($db->error);
- // Data set length after filtering
- $sQuery = "SELECT FOUND_ROWS()";
- $rResultFilterTotal = $db->query( $sQuery ) or die($db->error);
- list($iFilteredTotal) = $rResultFilterTotal->fetch_row();
- // Total data set length
- $sQuery = "SELECT COUNT(`".$sIndexColumn."`) FROM `".$sTable."`";
- $rResultTotal = $db->query( $sQuery ) or die($db->error);
- list($iTotal) = $rResultTotal->fetch_row();
- /**
- * Output
- */
- $output = array(
- "sEcho" => intval($input['sEcho']),
- "iTotalRecords" => $iTotal,
- "iTotalDisplayRecords" => $iFilteredTotal,
- "aaData" => array(),
- );
- // Looping Data
- while ( $aRow = $rResult->fetch_assoc() ) {
- $row = array();
- $btn = '<a href="#" onClick="showModals(\''.$aRow['id'].'\')">Edit</a> | <a href="#" onClick="deleteUser(\''.$aRow['id'].'\')">delete</a>';
- for ( $i=0 ; $i<$iColumnCount ; $i++ ) {
- $row[] = $aRow[ $aColumns[$i] ];
- }
- $row = array( $btn, $aRow['nik'], $aRow['nama'],$aRow['nopol'],$aRow['cabang'] );
- $output['aaData'][] = $row;
- }
- echo json_encode( $output );
- ?>
- --------------------------------------------------------------- su-proses------------------------------------------------------
- <?php
- include"config/koneksi.php";
- switch ($_POST['type']) {
- //Tampilkan Data
- case "get":
- $SQL = mysqli_query($db, "SELECT * FROM supir,staff where staff.nik=supir.nik and supir.id='".$_POST['id']."'");
- $return = mysqli_fetch_array($SQL,MYSQLI_ASSOC);
- echo json_encode($return);
- break;
- //Tambah Data
- case "new":
- //serid = date("ymdhis")."_".rand(0,10);
- $SQL = mysqli_query($db,
- "INSERT INTO supir SET
- id=UPPER('".$_POST['id']."'),
- nik=UPPER('".$_POST['nik']."'),
- nopol=UPPER('".$_POST['nopol']."'),
- cabang=UPPER('".$_POST['cabang']."')
- ");
- if($SQL){
- echo json_encode("OK")or die("Salah Di ".mysqli_error);
- }
- break;
- //Edit Data
- case "edit":
- $SQL = mysqli_query($db,
- "UPDATE supir SET
- nik=UPPER('".$_POST['nik']."'),
- nopol=UPPER('".$_POST['nopol']."'),
- cabang=UPPER('".$_POST['cabang']."')
- WHERE id='".$_POST['id']."'
- ");
- if($SQL){
- echo json_encode("OK")or die("Salah Di ".mysqli_error);
- }
- break;
- //Hapus Data
- case "delete":
- $SQL = mysqli_query($db, "DELETE FROM supir WHERE id='".$_POST['id']."'");
- if($SQL){
- echo json_encode("OK")or die("Salah Di ".mysqli_error);
- }
- break;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement