Advertisement
Guest User

datatable serverside script

a guest
May 20th, 2011
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.33 KB | None | 0 0
  1. /* Paging */
  2.         $sLimit = "";
  3.         if ( isset( $_POST['iDisplayStart'] ) )
  4.         {
  5.                 $sLimit = " LIMIT ".mysql_real_escape_string( $_POST['iDisplayStart'] ).", ".
  6.                         mysql_real_escape_string( $_POST['iDisplayLength'] );
  7.         }
  8.  
  9.  
  10.         $sOrder ="";
  11.         if ( isset( $_POST['iSortCol_0'] ) )
  12.         {
  13.                 $sOrder = "ORDER BY Date, A.Line";
  14.                  }
  15.  
  16. $sWhere = "";
  17. //      if ( $_POST['sSearch'] != "" )
  18.         if (postVar('sSearch') !="" )
  19.         {
  20.                 $sWhere = " WHERE (A.Inspection_datetime LIKE '%".mysql_real_escape_string( $_POST['sSearch'] )."%' OR
  21.                                A.Line LIKE '%".mysql_real_escape_string( $_POST['sSearch'] )."%' OR ".
  22.                                " A.Model LIKE '%".mysql_real_escape_string( $_POST['sSearch'] )."%' OR ".
  23.                                " A.Lot_no LIKE '%".mysql_real_escape_string( $_POST['sSearch'] )."%' OR ".
  24.                                " A.Range_sampling LIKE '%".mysql_real_escape_string( $_POST['sSearch'] )."%' OR ".
  25. //                             " A.Serial_number LIKE '%".mysql_real_escape_string( $_POST['sSearch'] )."%' OR ".
  26.                                " B.name LIKE '%".mysql_real_escape_string( $_POST['sSearch'] )."%') ";
  27.         }
  28.  
  29. $sGroupBy = " GROUP BY A.Range_sampling, A.Lot_no ";
  30.                 $sQuery = "SELECT DATE(A.Inspection_datetime) AS Date, A.Line, A.Model,
  31.                                  A.Lot_no,A.Range_sampling,COUNT(A.Serial_number) AS Error,B.name AS PIC
  32.                           FROM inspection_report A
  33.                           LEFT JOIN Employee B
  34.                           ON A.NIK=B.NIK
  35.                           WHERE CHAR_LENGTH( A.Range_sampling ) < 17
  36.                           AND MONTH(A.Inspection_datetime)=MONTH(CURRENT_DATE)" .$sWhere.$sGroupBy.$sOrder.$sLimit;
  37.         $rResult = mysql_query( $sQuery) or _doError(_ERROR30 . ' (<small>' . htmlspecialchars($sql) . '</small>): ' . mysql_error() );  // submit SQL to MySQL and err$
  38.  
  39.         $sQuery = "SELECT FOUND_ROWS()";
  40.         $rResultFilterTotal = mysql_query( $sQuery) or _doError(_ERROR30 . ' (<small>' . htmlspecialchars($sql) . '</small>): ' . mysql_error() );  // submit SQL to My$
  41.         $aResultFilterTotal = mysql_fetch_array($rResultFilterTotal);
  42.         $iFilteredTotal = $aResultFilterTotal[0];
  43.  
  44.         $sQuery = "SELECT COUNT(Line) FROM   inspection_report";
  45.  
  46.         $rResultTotal = mysql_query( $sQuery) or _doError(_ERROR30 . ' (<small>' . htmlspecialchars($sql) . '</small>): ' . mysql_error() );  // submit SQL to MySQL an$
  47.         $aResultTotal = mysql_fetch_array($rResultTotal);
  48.         $iTotal = $aResultTotal[0];
  49.  
  50. $sOutput = '{';
  51.         $sOutput .= '"sEcho": '.intval($_POST['sEcho']).',';     //   '.intval($_POST['sEcho']).', ';
  52.         $sOutput .= '"iTotalRecords": '.$iTotal.', ';
  53. //      $sOutput .= '"iTotalDisplayRecords": '.$iFilteredTotal.', \';
  54.         $sOutput .= '"iTotalDisplayRecords": '.$iTotal.', ';
  55.         $sOutput .= '"aaData": [ ';
  56.         while ( $aRow = mysql_fetch_array( $rResult ) )
  57.         {
  58.                 $sOutput .= "[";
  59.                 $sOutput .= '"'.addslashes($aRow['Date']).'",';
  60.                 $sOutput .= '"'.addslashes($aRow['Line']).'",';
  61.                 $sOutput .= '"'.addslashes($aRow['Model']).'",';
  62.                 $sOutput .= '"'.addslashes($aRow['Lot_no']).'",';
  63.                 $sOutput .= '"'.addslashes($aRow['Range_sampling']).'",';
  64.                 $sOutput .= '"'.addslashes($aRow['Error']).'",';
  65.                 $sOutput .= '"'.addslashes($aRow['PIC']).'"';
  66.                 $sOutput .= "],";
  67.         }
  68.         $sOutput = substr_replace( $sOutput, "", -1 );
  69.         $sOutput .= '] }';
  70.  
  71.         echo $sOutput;
  72.  
  73. function fnColumnToField( $i )
  74.         {
  75.                 if ( $i == 0 )
  76.                         return "Date";
  77.                 else if ( $i == 1 )
  78.                         return "Line";
  79.                 else if ( $i == 2 )
  80.                         return "Model";
  81.                 else if ( $i == 3 )
  82.                         return "Lot_no";
  83.                 else if ( $i == 4 )
  84.                         return "Range_sampling";
  85.                 else if ( $i == 5 )
  86.                         return "Error";
  87.                 else if ( $i == 6 )
  88.                         return "PIC";
  89.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement