3 include( $_SERVER['DOCUMENT_ROOT']."/datatables/mysql.php" ); /* ;-) */
8 function fatal_error ( $sErrorMessage = '' )
10 header( $_SERVER['SERVER_PROTOCOL'] .' 500 Internal Server Error' );
11 die( $sErrorMessage );
18 if ( ! $gaSql['link'] = mysql_pconnect( $gaSql['server'], $gaSql['user'], $gaSql['password'] ) )
20 fatal_error( 'Could not open connection to server' );
23 if ( ! mysql_select_db( $gaSql['db'], $gaSql['link'] ) )
25 fatal_error( 'Could not select database ' );
32 if ( isset( $_GET['iDisplayStart'] ) && $_GET['iDisplayLength'] != '-1' )
34 $sLimit = "LIMIT ".intval( $_GET['iDisplayStart'] ).", ".
35 intval( $_GET['iDisplayLength'] );
39 if ( isset( $_GET['iSortCol_0'] ) )
41 $sOrder = "ORDER BY ";
42 for ( $i=0 ; $i<mysql_real_escape_string( $_GET['iSortingCols'] ) ; $i++ )
44 $sOrder .= fnColumnToField(mysql_real_escape_string( $_GET['iSortCol_'.$i] ))."
45 ".mysql_real_escape_string( $_GET['sSortDir_'.$i] ) .", ";
47 $sOrder = substr_replace( $sOrder, "", -2 );
50 /* Filtering - NOTE this does not match the built-in DataTables filtering which does it
51 * word by word on any field. It's possible to do here, but concerned about efficiency
52 * on very large tables, and MySQL's regex functionality is very limited
55 if ( $_GET['sSearch'] != "" )
57 $sWhere = "WHERE ( engine LIKE '%".mysql_real_escape_string( $_GET['sSearch'] )."%' OR ".
58 "browser LIKE '%".mysql_real_escape_string( $_GET['sSearch'] )."%' OR ".
59 "platform LIKE '%".mysql_real_escape_string( $_GET['sSearch'] )."%' OR ".
60 "version LIKE '%".mysql_real_escape_string( $_GET['sSearch'] )."%' OR ".
61 "grade LIKE '%".mysql_real_escape_string( $_GET['sSearch'] )."%' )";
64 for ( $i=0 ; $i<$_GET['iColumns'] ; $i++ )
66 if ( $_GET['sSearch_'.$i] != '' )
76 $sWhere .= fnColumnToField($i) ." LIKE '%".mysql_real_escape_string( $_GET['sSearch_'.$i] )."%'";
81 SELECT SQL_CALC_FOUND_ROWS id, engine, browser, platform, version, grade
87 $rResult = mysql_query( $sQuery, $gaSql['link'] ) or fatal_error( 'MySQL Error: ' . mysql_errno() );
92 $rResultFilterTotal = mysql_query( $sQuery, $gaSql['link'] ) or fatal_error( 'MySQL Error: ' . mysql_errno() );
93 $aResultFilterTotal = mysql_fetch_array($rResultFilterTotal);
94 $iFilteredTotal = $aResultFilterTotal[0];
100 $rResultTotal = mysql_query( $sQuery, $gaSql['link'] ) or fatal_error( 'MySQL Error: ' . mysql_errno() );
101 $aResultTotal = mysql_fetch_array($rResultTotal);
102 $iTotal = $aResultTotal[0];
105 $sOutput .= '"sEcho": '.intval($_GET['sEcho']).', ';
106 $sOutput .= '"iTotalRecords": '.$iTotal.', ';
107 $sOutput .= '"iTotalDisplayRecords": '.$iFilteredTotal.', ';
108 $sOutput .= '"aaData": [ ';
109 while ( $aRow = mysql_fetch_array( $rResult ) )
112 $sOutput .= '"'.str_replace('"', '\"', $aRow['engine']).'",';
113 $sOutput .= '"'.str_replace('"', '\"', $aRow['browser']).'",';
114 $sOutput .= '"'.str_replace('"', '\"', $aRow['platform']).'",';
115 if ( $aRow['version'] == "0" )
118 $sOutput .= '"'.str_replace('"', '\"', $aRow['version']).'",';
119 $sOutput .= '"'.str_replace('"', '\"', $aRow['grade']).'"';
122 $sOutput = substr_replace( $sOutput, "", -1 );
128 function fnColumnToField( $i )