首先,讓我指定我不知道JSON的工作原理。我不是一個強大的編碼員。當我改變!=
到==
那裏說$sWhere .= "status == '".APS_DONE."'";
我得到的說,一個JSON解析錯誤:JSON數據表錯誤
「的DataTable警告:從服務器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);
?>
JSON在哪裏? –
這看起來像SQL代碼。 – luiscubal
json不「工作」。它只是一個javascript數據結構的文本表示。幾乎字面上它是JS中變量賦值的右邊,例如'var foo = this_is_the_json_here'。 –