Quantcast
Channel: DataTables 1.9 — DataTables forums
Viewing all articles
Browse latest Browse all 1816

PHP/MSSQL returns $secho on server_processing.php page

$
0
0
Good evening,

I've been pulling my hair out over this and can't seem to identify where the issue lies. When I run the HTML page it indicates the JSON cannot be parsed and is invalid, however, when I run the server processing file all it returns is the secho query

"SELECT TOP 10 Filename,SenderId,ReceiverId,ControlNumber FROM Interchange WHERE SenderId NOT IN ( SELECT SenderId FROM ( SELECT TOP 0 Filename,SenderId,ReceiverId,ControlNumber FROM Interchange ) as [virtTable] ) : Array"

I'm not sure where to go from here, I've searched the forums high and low and can't seam to find a similar example. Any help in resolving this issue would be greatly appreciated.

Here is the link to the debug http://debug.datatables.net/acofiq

Thanks!

Here is my server processing file
<?php
    /* Indexed column (used for fast and accurate table cardinality) */
    $sIndexColumn = "SenderId";
        
    /* DB table to use */
    $sTable = "Interchange";
     
        $gaSql['server'] = "LPV-FINCSFS01\EDID";
        $gaSql['db'] = "999";
        $connectionInfo = array("Database"=>$gaSql['db'],"ReturnDatesAsStrings"=>true);
        $gaSql['link'] = sqlsrv_connect( $gaSql['server'], $connectionInfo);
        $params = array('Filename', 'SenderId', 'RecieverId', 'ControlNumber');
          
    /*
    * Columns
    * If you don't want all of the columns displayed you need to hardcode $aColumns array with your elements.
    * If not this will grab all the columns associated with $sTable
    */
    $aColumns = array('Filename', 'SenderId', 'ReceiverId', 'ControlNumber');
  
  
    /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
     * If you just want to use the basic configuration for DataTables with PHP server-side, there is
     * no need to edit below this line
     */
     
    /* Ordering */
    $sOrder = "";
    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] ) ]."
                    ".addslashes( $_GET['sSortDir_'.$i] ) .", ";
            }
        }
        $sOrder = substr_replace( $sOrder, "", -2 );
        if ( $sOrder == "ORDER BY" ) {
            $sOrder = "";
        }
    }
        
    /* Filtering */
    $sWhere = "";
    if ( isset($_GET['sSearch']) && $_GET['sSearch'] != "" ) {
        $sWhere = "WHERE (";
        for ( $i=0 ; $i<count($aColumns) ; $i++ ) {
            $sWhere .= $aColumns[$i]." LIKE '%".addslashes( $_GET['sSearch'] )."%' OR ";
        }
        $sWhere = substr_replace( $sWhere, "", -3 );
        $sWhere .= ')';
    }
    /* Individual column filtering */
    for ( $i=0 ; $i<count($aColumns) ; $i++ ) {
        if ( isset($_GET['bSearchable_'.$i]) && $_GET['bSearchable_'.$i] == "true" && $_GET['sSearch_'.$i] != '' )  {
            if ( $sWhere == "" ) {
                $sWhere = "WHERE ";
            } else {
                $sWhere .= " AND ";
            }
            $sWhere .= $aColumns[$i]." LIKE '%".addslashes($_GET['sSearch_'.$i])."%' ";
        }
    }
        
    /* Paging */
     $top = (isset($_GET['iDisplayStart']))?((int)$_GET['iDisplayStart']):0 ;
    $limit = (isset($_GET['iDisplayLength']))?((int)$_GET['iDisplayLength'] ):10;
    $sQuery = "SELECT TOP $limit ".implode(",",$aColumns)."
        FROM $sTable
        $sWhere ".(($sWhere=="")?" WHERE ":" AND ")." $sIndexColumn NOT IN
        (
            SELECT $sIndexColumn FROM
            (
                SELECT TOP $top ".implode(",",$aColumns)."
                FROM $sTable
                $sWhere
                $sOrder
            )
            as [virtTable]
        )
        $sOrder";
      
    $rResult = sqlsrv_query($gaSql['link'],$sQuery) or die("$sQuery: " . sqlsrv_errors());
   
    $sQueryCnt = "SELECT * FROM $sTable $sWhere";
    $rResultCnt = sqlsrv_query( $gaSql['link'], $sQueryCnt ,$params, $options) or die (" $sQueryCnt: " . sqlsrv_errors());
    $iFilteredTotal = sqlsrv_num_rows( $rResultCnt );
   
    $sQuery = " SELECT * FROM $sTable ";
    $rResultTotal = sqlsrv_query( $gaSql['link'], $sQuery ,$params, $options) or die(sqlsrv_errors());
    $iTotal = sqlsrv_num_rows( $rResultTotal );
        
    $output = array(
        "sEcho" => intval($_GET['sEcho']),
        "iTotalRecords" => $iTotal,
        "iTotalDisplayRecords" => $iFilteredTotal,
        "aaData" => array()
    );
        
    while ( $aRow = sqlsrv_fetch_array( $rResult ) ) {
        $row = array();
        for ( $i=0 ; $i<count($aColumns) ; $i++ ) {
            if ( $aColumns[$i] != ' ' ) {
                $v = $aRow[ $aColumns[$i] ];
                $v = mb_check_encoding($v, 'UTF-8') ? $v : utf8_encode($v);
                $row[]=$v;
            }
        }
        If (!empty($row)) { $output['aaData'][] = $row; }
    }  
    echo json_encode( $output );
?>

and here is my .html file
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
                 
        <title>999 Reconciliation</title>
    <style type="text/css" title="currentStyle">
        @import "/dt/media/css/demo_page.css"; @import "/dt/media/css/header.css";
            @import "/dt/media/css/demo_table_jui.css";
            @import "/dt/examples/examples_support/themes/ui-lightness/jquery-ui-1.8.4.custom.css";
</style>
        <script type="text/javascript" language="javascript" src="/dt/media/js/jquery.js"></script>
        <script type="text/javascript" language="javascript" src="/dt/media/js/jquery.dataTables.js"></script>
<script type="text/javascript">
    // data table basic initialisation
    jQuery(document).ready(function() {
  $('#Test').dataTable( {
        "bProcessing": true,
        "bServerSide": true,
        "sAjaxSource": "/dt/examples/server_side/scripts/server_processing.php"
    } );
 });
</script>
 
    </head>
 
<body id="dt_example">
        <div id="container">
            <h1>999 Reconciliation</h1>
            <div id="dynamic">
                <table cellpadding="0" cellspacing="0" border="0" class="display" id="Test">
                    <thead>
                        <tr>
                            <th width="25%">Filename</th>
                            <th width="25%">SenderId</th>
                            <th width="25%">ReceiverId</th>
                            <th width="25%">ControlNumber</th>
                            </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td colspan="5" class="dataTables_empty">Loading data from server</td>
                        </tr>
                    </tbody>
                </table>
            </div>
    </body>
      
</html>

Viewing all articles
Browse latest Browse all 1816

Trending Articles