まず、JSON がどのように機能するのかまったくわかりません。そして、私は決して強力なコーダーではありません。それが言う場所に変更!=
すると、 次のような JSON 解析エラーが発生します。==
$sWhere .= "status == '".APS_DONE."'";
「DataTables 警告: サーバーからの JSON データを解析できませんでした。これは、JSON フォーマット エラーが原因です。」
それが何を意味するかについての手がかり。
<?php
include('aps2.database.php');
include('aps2.login.php');
*********** COMPLETED REQUEST PROCESSING CODE
$sTable = 'aps2_requests';
$aColumns = array( 'rid', 'description', 'creatoruid', 'photoguid');
$sIndexColumn = 'description';
$sLimit = "";
if ( isset( $_GET['iDisplayStart'] ) && $_GET['iDisplayLength'] != '-1' )
{
$sLimit = "LIMIT ".mysql_real_escape_string( $_GET['iDisplayStart'] ).", ".
mysql_real_escape_string( $_GET['iDisplayLength'] );
}
if ( isset( $_GET['iSortCol_0'] ) )
{
$sOrder = "ORDER BY ";
for ( $i=0 ; $i<intval( $_GET['iSortingCols'] ) ; $i++ )
{
if ( $_GET[ 'bSortable_'.intval($_GET['iSortCol_'.$i]) ] == "true" )
{
$sOrder .= $aColumns[ intval( $_GET['iSortCol_'.$i] ) ]."
".mysql_real_escape_string( $_GET['sSortDir_'.$i] ) .", ";
}
}
$sOrder = substr_replace( $sOrder, "", -2 );
if ( $sOrder == "ORDER BY" )
{
$sOrder = "";
}
}
$sWhere = "";
if ( $_GET['sSearch'] != "" )
{
$sWhere = "WHERE (";
for ( $i=0 ; $i<count($aColumns) ; $i++ )
{
$sWhere .= $aColumns[$i]." LIKE '%".mysql_real_escape_string( $_GET['sSearch'] )."%' OR ";
}
$sWhere = substr_replace( $sWhere, "", -3 );
$sWhere .= ')';
}
/* Individual column filtering */
for ( $i=0 ; $i<count($aColumns) ; $i++ )
{
if ( $_GET['bSearchable_'.$i] == "true" && $_GET['sSearch_'.$i] != '' )
{
if ( $sWhere == "" )
{
$sWhere = "WHERE ";
}
else
{
$sWhere .= " AND ";
}
$sWhere .= $aColumns[$i]." LIKE '%".mysql_real_escape_string($_GET['sSearch_'.$i])."%' ";
}
}
if(strlen($sWhere) > 1)
{
$sWhere .= " AND ";
}
else
{
$sWhere = "WHERE ";
}
$sWhere .= "status == '".APS_DONE."'";
/*
* SQL queries
* Get data to display
*/
$sQuery = "
SELECT SQL_CALC_FOUND_ROWS ".str_replace(" , ", " ", implode(", ", $aColumns))."
FROM $sTable
$sWhere
$sOrder
$sLimit
";
$rResult = mysql_query( $sQuery ) or die(mysql_error());
/* Data set length after filtering */
$sQuery = "
SELECT FOUND_ROWS()
";
$rResultFilterTotal = mysql_query( $sQuery ) or die(mysql_error());
$aResultFilterTotal = mysql_fetch_array($rResultFilterTotal);
$iFilteredTotal = $aResultFilterTotal[0];
/* Total data set length */
$sQuery = "
SELECT COUNT(".$sIndexColumn.")
FROM $sTable
";
$rResultTotal = mysql_query( $sQuery ) or die(mysql_error());
$aResultTotal = mysql_fetch_array($rResultTotal);
$iTotal = $aResultTotal[0];
/*
* Output
*/
$output = array(
"sEcho" => intval($_GET['sEcho']),
"iTotalRecords" => $iTotal,
"iTotalDisplayRecords" => $iFilteredTotal,
"aaData" => array()
);
while ( $aRow = mysql_fetch_array( $rResult ) )
{
$row = array();
for ( $i=0 ; $i<count($aColumns) ; $i++ )
{
if ( $aColumns[$i] == "version" )
{
$row[] = ($aRow[ $aColumns[$i] ]=="0") ? '-' : $aRow[ $aColumns[$i] ];
}
else if ( $aColumns[$i] != ' ' )
{
if ($aColumns[$i] == 'creatoruid')
{
$row[] = '<p style="margin: 5px;">' . aps2_user_name_from_uid($aRow[$aColumns[$i]]) . '</p>';
}
else if ($aColumns[$i] == 'photoguid')
{
$row[] = '<p style="margin: 5px;">' . aps2_get_request_photographer_or_status($aRow['rid']) . '</p>';
}
else if ($aColumns[$i] == 'description')
{
$row[] = '<p style="margin: 5px 10px;line-height: 1.2em;">' . stripslashes(preview_text_truncate($aRow[ $aColumns[$i] ])) . '</p>';
}
else
{
$row[] = $aRow[ $aColumns[$i] ];
}
}
}
$status = aps2_get_request_status($aRow['rid']);
$actionButtons = '<a class="actionbutton greenlink viewbutton" href="' . $aRow['rid'] . '">View</a>';
$actionButtons .= '<a class="actionbutton greenlink uploadbutton" href="' . $aRow['rid'] . '">Upload</a>';
if (($status == APS_UNASSIGNED || $status == APS_IN_PROGRESS) && aps2_get_user_role($_SESSION['uid']) > APS_STANDARD)
{
$actionButtons .= '<a class="actionbutton greenlink acceptbutton" href="' . $aRow['rid'] . '">Accept</a>';
}
if (($aRow['creatoruid'] == $_SESSION['uid'] && aps2_get_request_status($aRow['rid']) == APS_UNASSIGNED) || $_SESSION['uid'] == 1)
{
$actionButtons .= '<a class="actionbutton greenlink deletebutton" href="' . $aRow['rid'] . '">Delete</a>';
}
$row[] = '<div style="margin:3px 3px 6px 3px;text-align:center;">'.$actionButtons.'</div>';
$output['aaData'][] = $row;
}
echo json_encode( $output );
?>