php - JSON Datatable error -
to start, let me specify have no clue how json works. , in no way strong coder. when change !=
==
says $swhere .= "status == '".aps_done."'";
json parse error says:
"datatables warning: json data server not parsed. caused json formatting error."
any clue means.
<?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 "; ( $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 ("; ( $i=0 ; $i<count($acolumns) ; $i++ ) { $swhere .= $acolumns[$i]." '%".mysql_real_escape_string( $_get['ssearch'] )."%' or "; } $swhere = substr_replace( $swhere, "", -3 ); $swhere .= ')'; } /* individual column filtering */ ( $i=0 ; $i<count($acolumns) ; $i++ ) { if ( $_get['bsearchable_'.$i] == "true" && $_get['ssearch_'.$i] != '' ) { if ( $swhere == "" ) { $swhere = "where "; } else { $swhere .= " , "; } $swhere .= $acolumns[$i]." '%".mysql_real_escape_string($_get['ssearch_'.$i])."%' "; } } if(strlen($swhere) > 1) { $swhere .= " , "; } else { $swhere = "where "; } $swhere .= "status == '".aps_done."'"; /* * sql queries * data display */ $squery = " select sql_calc_found_rows ".str_replace(" , ", " ", implode(", ", $acolumns))." $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.") $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(); ( $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 ); ?>
this code generates sql code , executes it.
when have $swhere .= "status != '".aps_done."'";
looks table rows status not equal aps_done.
there no ==
operator in mysql (see list yourself), when replace != == invalid sql code.
i'm guessing outputs mysql error message not valid json.
use =
instead of ==
.
Comments
Post a Comment