mirror of
https://github.com/DataTables/DataTables.git
synced 2025-02-19 17:54:14 +01:00
Updated: Server-side example scripts brought up-to-date
This commit is contained in:
parent
1e9436cc5e
commit
1f65b1187f
@ -75,6 +75,12 @@
|
||||
|
||||
<h1>Server side (PHP) code</h1>
|
||||
<pre><?php
|
||||
/*
|
||||
* Script: DataTables server-side script for PHP and MySQL
|
||||
* Copyright: 2010 - Allan Jardine
|
||||
* License: GPL v2 or BSD (3-point)
|
||||
*/
|
||||
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Easy set variables
|
||||
*/
|
||||
@ -216,44 +222,33 @@
|
||||
/*
|
||||
* Output
|
||||
*/
|
||||
$sOutput = '{';
|
||||
$sOutput .= '"sEcho": '.intval($_GET['sEcho']).', ';
|
||||
$sOutput .= '"iTotalRecords": '.$iTotal.', ';
|
||||
$sOutput .= '"iTotalDisplayRecords": '.$iFilteredTotal.', ';
|
||||
$sOutput .= '"aaData": [ ';
|
||||
$output = array(
|
||||
"sEcho" => intval($_GET['sEcho']),
|
||||
"iTotalRecords" => $iTotal,
|
||||
"iTotalDisplayRecords" => $iFilteredTotal,
|
||||
"aaData" => array()
|
||||
);
|
||||
|
||||
while ( $aRow = mysql_fetch_array( $rResult ) )
|
||||
{
|
||||
$sOutput .= "[";
|
||||
$row = array();
|
||||
for ( $i=0 ; $i<count($aColumns) ; $i++ )
|
||||
{
|
||||
if ( $aColumns[$i] == "version" )
|
||||
{
|
||||
/* Special output formatting for 'version' */
|
||||
$sOutput .= ($aRow[ $aColumns[$i] ]=="0") ?
|
||||
'"-",' :
|
||||
'"'.str_replace('"', '\"', $aRow[ $aColumns[$i] ]).'",';
|
||||
/* Special output formatting for 'version' column */
|
||||
$row[] = ($aRow[ $aColumns[$i] ]=="0") ? '-' : $aRow[ $aColumns[$i] ];
|
||||
}
|
||||
else if ( $aColumns[$i] != ' ' )
|
||||
{
|
||||
/* General output */
|
||||
$sOutput .= '"'.str_replace('"', '\"', $aRow[ $aColumns[$i] ]).'",';
|
||||
$row[] = $aRow[ $aColumns[$i] ];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Optional Configuration:
|
||||
* If you need to add any extra columns (add/edit/delete etc) to the table, that aren't in the
|
||||
* database - you can do it here
|
||||
*/
|
||||
|
||||
|
||||
$sOutput = substr_replace( $sOutput, "", -1 );
|
||||
$sOutput .= "],";
|
||||
$output['aaData'][] = $row;
|
||||
}
|
||||
$sOutput = substr_replace( $sOutput, "", -1 );
|
||||
$sOutput .= '] }';
|
||||
|
||||
echo $sOutput;
|
||||
echo json_encode( $output );
|
||||
?></pre>
|
||||
|
||||
|
||||
|
@ -74,6 +74,12 @@
|
||||
|
||||
<h1>Server side (PHP) code</h1>
|
||||
<pre><?php
|
||||
/*
|
||||
* Script: DataTables server-side script for PHP and MySQL
|
||||
* Copyright: 2010 - Allan Jardine
|
||||
* License: GPL v2 or BSD (3-point)
|
||||
*/
|
||||
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Easy set variables
|
||||
*/
|
||||
@ -215,44 +221,33 @@
|
||||
/*
|
||||
* Output
|
||||
*/
|
||||
$sOutput = '{';
|
||||
$sOutput .= '"sEcho": '.intval($_GET['sEcho']).', ';
|
||||
$sOutput .= '"iTotalRecords": '.$iTotal.', ';
|
||||
$sOutput .= '"iTotalDisplayRecords": '.$iFilteredTotal.', ';
|
||||
$sOutput .= '"aaData": [ ';
|
||||
$output = array(
|
||||
"sEcho" => intval($_GET['sEcho']),
|
||||
"iTotalRecords" => $iTotal,
|
||||
"iTotalDisplayRecords" => $iFilteredTotal,
|
||||
"aaData" => array()
|
||||
);
|
||||
|
||||
while ( $aRow = mysql_fetch_array( $rResult ) )
|
||||
{
|
||||
$sOutput .= "[";
|
||||
$row = array();
|
||||
for ( $i=0 ; $i<count($aColumns) ; $i++ )
|
||||
{
|
||||
if ( $aColumns[$i] == "version" )
|
||||
{
|
||||
/* Special output formatting for 'version' */
|
||||
$sOutput .= ($aRow[ $aColumns[$i] ]=="0") ?
|
||||
'"-",' :
|
||||
'"'.str_replace('"', '\"', $aRow[ $aColumns[$i] ]).'",';
|
||||
/* Special output formatting for 'version' column */
|
||||
$row[] = ($aRow[ $aColumns[$i] ]=="0") ? '-' : $aRow[ $aColumns[$i] ];
|
||||
}
|
||||
else if ( $aColumns[$i] != ' ' )
|
||||
{
|
||||
/* General output */
|
||||
$sOutput .= '"'.str_replace('"', '\"', $aRow[ $aColumns[$i] ]).'",';
|
||||
$row[] = $aRow[ $aColumns[$i] ];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Optional Configuration:
|
||||
* If you need to add any extra columns (add/edit/delete etc) to the table, that aren't in the
|
||||
* database - you can do it here
|
||||
*/
|
||||
|
||||
|
||||
$sOutput = substr_replace( $sOutput, "", -1 );
|
||||
$sOutput .= "],";
|
||||
$output['aaData'][] = $row;
|
||||
}
|
||||
$sOutput = substr_replace( $sOutput, "", -1 );
|
||||
$sOutput .= '] }';
|
||||
|
||||
echo $sOutput;
|
||||
echo json_encode( $output );
|
||||
?></pre>
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user