fnServerData: unable to display data containing letter(s)

fnServerData: unable to display data containing letter(s)

swarabhaskaraswarabhaskara Posts: 5Questions: 0Answers: 0
edited December 2011 in General
This is supposedly very easy but I've been unable to resolve it.

I am trying to use fnServerData :
[code]
"fnServerData" : function ( sSource, aoData, fnCallback ) {
// push parameter onto the aoData array.
aoData.push( { "name": "kd_skpd", "value": "12003B" } );

// send request to server, use default fnCallback to process returned JSON
$jx.ajax( {
"dataType": 'json',
"type": "GET",
"url": sSource,
"cache": false,
"data": aoData,
"success": fnCallback
} );
},
[/code]

and in the serverside_processing.php I added the following to the where clause:
[code]
if ( isset($_GET['kd_skpd']) && $_GET['kd_skpd'] != "" ) {
if ($sWhere) $sWhere .= " AND kd_skpd=".mysql_real_escape_string( $_GET['kd_skpd'] );
else $sWhere = " WHERE kd_skpd=".mysql_real_escape_string( $_GET['kd_skpd'] );
}
[/code]

The error I get is Unknown column '12003B' in 'where clause', but if I change the value, for example, to "12003", DataTables displays the data correctly, including kode_skpd = "12003B". And, if I change the value with a numeric value that is not available under the field kode_skpd, for example "99999", the DataTables popped up the expected "No Data Found" info.

So, the code basically only works for me if the value is numeric but it doesn't if the value is a text? Please help. Thank you in advance.

Replies

  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    edited December 2011
    put single quotes around the kb_skpd value in your $sWhere

    [code]
    if ( isset($_GET['kd_skpd']) && $_GET['kd_skpd'] != "" ) {
    if ($sWhere) $sWhere .= " AND kd_skpd='".mysql_real_escape_string( $_GET['kd_skpd'] )."' ";
    else $sWhere = " WHERE kd_skpd='".mysql_real_escape_string( $_GET['kd_skpd'] ). "' ";
    }
    [/code]
  • swarabhaskaraswarabhaskara Posts: 5Questions: 0Answers: 0
    Thanks big time. You're the man
This discussion has been closed.