Notice: Undefined index: sEcho

Notice: Undefined index: sEcho

gregshogungregshogun Posts: 3Questions: 0Answers: 0
edited March 2013 in General
Hello all,

I test the server-side processing and I'm stuck on an issue.

The first time I load the table my data appear and everything is OK but the pagination and
the sort system don't work.

In my JSON the variable sEcho is equal to 0.
So this is a problem in my server-side code.

After debbuging, It's due to impossibility of finding all variables in GET.
All my $_GET variables is equal to null (!isset($_GET['sEcho'])).

In my client-side code I have this:
[code]
$(document).ready(function() {
$('#dataTable').dataTable(
{ "bProcessing": true,
"bServerSide": true,
"sAjaxSource": "testtableau/afficheTableau2.php"
});
});
[/code]

Any solutions?

Replies

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Please link to a test page showing this issue.

    Allan
  • gregshogungregshogun Posts: 3Questions: 0Answers: 0
    edited March 2013
    Hi Allan! Thanks for your response.

    The problem is that the page is on intranet...

    I have wrote the server-side script to use ADODB and MS SQL:
    [code]
    <?php
    //error_reporting(E_ALL);
    //ini_set('display_errors','On');

    /* Indexed column (used for fast and accurate table cardinality) */
    $sIndexColumn = "[N_IDHISTVALIDGED]";

    $sTable = "[T_HISTVALIDGED]";
    /*
    * 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('[N_ID]','[C_CPTANA]','[C_LIBFOUR]','[C_DEVISE]');

    /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
    * If you just want to use the basic configuration for DataTables with PHP server-side, there is
    * no need to edit below this line
    */

    $conn = new COM("ADODB.Connection") or die("Impossible de démarrer une connexion ADO");
    $conn->open("PROVIDER=SQLOLEDB;SERVER=xxxx.xxxx.xx.xx;UID=xxxxxxxx;PWD=xxxxxxxxxx;DATABASE=xxx");

    /* 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 = $conn->execute($sQuery);

    $sQueryCnt = "SELECT * FROM $sTable $sWhere";
    $rResultCnt = $conn->execute($sQueryCnt);
    $cpt = 0;
    while(!$rResultCnt->EOF)
    {
    $cpt++;
    $rResultCnt->MoveNext();
    }
    $rResultCnt->MoveFirst();
    $iFilteredTotal = $cpt;


    $sQuery = " SELECT * FROM $sTable ";
    $rResultTotal = $conn->execute($sQuery);
    $cpt = 0;
    while(!$rResultTotal->EOF)
    {
    $cpt++;
    $rResultTotal->MoveNext();
    }
    $rResultTotal->MoveFirst();
    $iTotal = $cpt;

    $output = array(
    "sEcho" => intval($_GET['sEcho']),
    "iTotalRecords" => $iTotal,
    "iTotalDisplayRecords" => $iFilteredTotal,
    "aaData" => array()
    );

    while (!$rResult->EOF)
    {
    $aRow = array();
    for($j=0;$jfields[$j]->value);
    }
    $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;
    }
    //$aRow = null;
    $rResult->MoveNext();
    }

    echo json_encode($output);
    ?>

    [/code]
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    If you have a look at the 'Network' in Firefox or Chrome, is the sEcho parameter in the GET list? It certainly should be. Beyond that, i can't say too much I'm afraid, since I'm just guessing already :-)

    Allan
  • gregshogungregshogun Posts: 3Questions: 0Answers: 0
    When I look on 'Network' in Chrome I have one call to my server-side script (when I load the page).
    But this call aven't header parameters.

    When I try to do some actions (sort, pagin, etc.) there are no new calls in 'Network'.

    My problem seems to be mysterious...

    Anyway thank you for your help.
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Sounds like server-side processing isn't enabled. Can you run the table through the debugger please?

    Allan
This discussion has been closed.