1
0
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:
Allan Jardine 2011-01-25 18:06:36 +00:00
parent 1e9436cc5e
commit 1f65b1187f
2 changed files with 38 additions and 48 deletions

View File

@ -75,6 +75,12 @@
<h1>Server side (PHP) code</h1>
<pre>&lt;?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" =&gt; intval($_GET['sEcho']),
"iTotalRecords" =&gt; $iTotal,
"iTotalDisplayRecords" =&gt; $iFilteredTotal,
"aaData" =&gt; array()
);
while ( $aRow = mysql_fetch_array( $rResult ) )
{
$sOutput .= "[";
$row = array();
for ( $i=0 ; $i&lt;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 );
?&gt;</pre>

View File

@ -74,6 +74,12 @@
<h1>Server side (PHP) code</h1>
<pre>&lt;?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" =&gt; intval($_GET['sEcho']),
"iTotalRecords" =&gt; $iTotal,
"iTotalDisplayRecords" =&gt; $iFilteredTotal,
"aaData" =&gt; array()
);
while ( $aRow = mysql_fetch_array( $rResult ) )
{
$sOutput .= "[";
$row = array();
for ( $i=0 ; $i&lt;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 );
?&gt;</pre>