sEcho- The mystery variable.

sEcho- The mystery variable.

phpnewbiephpnewbie Posts: 14Questions: 0Answers: 0
edited June 2010 in General
Hello All,

I am trying to use the server side demo. I extracted all the contents and changed server_processing for my database settings.

Now, when I run server_side.html page, I see blank content, the table is not getting populated.

But, when I try to run just the server_processing.php page, I do get the data from the database.

I have been searching all across the forums and read about this sEcho variable which causes this problem.

Can someone please help me how to work around with this sEcho variable?

Many Thanks,

PHP Noob

Replies

  • allanallan Posts: 61,609Questions: 1Answers: 10,089 Site admin
    sEcho is described on this page: http://datatables.net/usage/server-side . It is simply information that DataTables needs to know about the data being sent back, in order to be able to render (Ajax is asynchronous remember, so results can come back out of order). At the moment all sEcho is, is an integer. You just need to pass back to DataTables the value that was sent (cast as an int for security).

    Allan
  • phpnewbiephpnewbie Posts: 14Questions: 0Answers: 0
    Hi Allan,

    Thank you so much for your quick reply.

    I do understand why sEcho is used, but, I fail to understand are we supposed to do anything with it?
    You said, you need to pass back to DataTables the value that was sent, can you please explain me how to do it (Sorry I have just started learning PHP).

    I tried this though,

    [code]

    $(document).ready(function() {
    $('#example').dataTable( {
    "bProcessing": true,
    "bServerSide": true,
    "sAjaxSource": "server.php?sEcho=1"
    } );
    } );


    [/code]

    Still no luck :-(
  • allanallan Posts: 61,609Questions: 1Answers: 10,089 Site admin
    You aren't supposed to do anything with it :-). On the client-side it is dealt with automatically by DataTables. On the server-side all you do is cast as int, and send it back. This example shows basic initialisation of server-side processing: http://datatables.net/examples/data_sources/server_side.html

    Allan
  • phpnewbiephpnewbie Posts: 14Questions: 0Answers: 0
    Hi Allan,

    Thanks again.. :-)

    I removed sEcho=1 from my client side.. I am using the exact code that is mentioned your in your example and the only change that I have made is database settings..

    Casting the sEcho as int is already done by your code here, [code]$sOutput .= '"sEcho": '.intval($_GET['sEcho']).', ';[/code]

    So practically, I have not changed anything.

    Now, when I try to open server_side.html, I see just a blank table with this message "Loading data from server".

    When I try to access the php page directly, I do get results in JSON format
    [code]
    {"sEcho": 0, "iTotalRecords": 57, "iTotalDisplayRecords": 57, "aaData": [ ["Trident","Internet Explorer 4.0","Win 95+","4","X"],["Trident","Internet Explorer 5.0","Win 95+","5","C"],["Trident","Internet Explorer 5.5","Win 95+","5.5","A"],["Trident","Internet Explorer 6","Win 98+","6","A"],["Trident","Internet Explorer 7","Win XP SP2+","7","A"],["Trident","AOL browser (AOL desktop)","Win XP","6","A"],["Gecko","Firefox 1.0","Win 98+ / OSX.2+","1.7","A"],["Gecko","Firefox 1.5","Win 98+ / OSX.2+","1.8","A"],["Gecko","Firefox 2.0","Win 98+ / OSX.2+","1.8","A"],["Gecko","Firefox 3.0","Win 2k+ / OSX.3+","1.9","A"],["Gecko","Camino 1.0","OSX.2+","1.8","A"],["Gecko","Camino 1.5","OSX.3+","1.8","A"],["Gecko","Netscape 7.2","Win 95+ / Mac OS 8.6-9.2","1.7","A"],["Gecko","Netscape Browser 8","Win 98SE+","1.7","A"],["Gecko","Netscape Navigator 9","Win 98+ / OSX.2+","1.8","A"],["Gecko","Mozilla 1.0","Win 95+ / OSX.1+","1","A"],["Gecko","Mozilla 1.1","Win 95+ / OSX.1+","1.1","A"],["Gecko","Mozilla 1.2","Win 95+ / OSX.1+","1.2","A"],["Gecko","Mozilla 1.3","Win 95+ / OSX.1+","1.3","A"],["Gecko","Mozilla 1.4","Win 95+ / OSX.1+","1.4","A"],["Gecko","Mozilla 1.5","Win 95+ / OSX.1+","1.5","A"],["Gecko","Mozilla 1.6","Win 95+ / OSX.1+","1.6","A"],["Gecko","Mozilla 1.7","Win 98+ / OSX.1+","1.7","A"],["Gecko","Mozilla 1.8","Win 98+ / OSX.1+","1.8","A"],["Gecko","Seamonkey 1.1","Win 98+ / OSX.2+","1.8","A"],["Gecko","Epiphany 2.20","Gnome","1.8","A"],["Webkit","Safari 1.2","OSX.3","125.5","A"],["Webkit","Safari 1.3","OSX.3","312.8","A"],["Webkit","Safari 2.0","OSX.4+","419.3","A"],["Webkit","Safari 3.0","OSX.4+","522.1","A"],["Webkit","OmniWeb 5.5","OSX.4+","420","A"],["Webkit","iPod Touch / iPhone","iPod","420.1","A"],["Webkit","S60","S60","413","A"],["Presto","Opera 7.0","Win 95+ / OSX.1+","-","A"],["Presto","Opera 7.5","Win 95+ / OSX.2+","-","A"],["Presto","Opera 8.0","Win 95+ / OSX.2+","-","A"],["Presto","Opera 8.5","Win 95+ / OSX.2+","-","A"],["Presto","Opera 9.0","Win 95+ / OSX.3+","-","A"],["Presto","Opera 9.2","Win 88+ / OSX.3+","-","A"],["Presto","Opera 9.5","Win 88+ / OSX.3+","-","A"],["Presto","Opera for Wii","Wii","-","A"],["Presto","Nokia N800","N800","-","A"],["Presto","Nintendo DS browser","Nintendo DS","8.5","C/A1"],["KHTML","Konqureror 3.1","KDE 3.1","3.1","C"],["KHTML","Konqureror 3.3","KDE 3.3","3.3","A"],["KHTML","Konqureror 3.5","KDE 3.5","3.5","A"],["Tasman","Internet Explorer 4.5","Mac OS 8-9","-","X"],["Tasman","Internet Explorer 5.1","Mac OS 7.6-9","1","C"],["Tasman","Internet Explorer 5.2","Mac OS 8-X","1","C"],["Misc","NetFront 3.1","Embedded devices","-","C"],["Misc","NetFront 3.4","Embedded devices","-","A"],["Misc","Dillo 0.8","Embedded devices","-","X"],["Misc","Links","Text only","-","X"],["Misc","Lynx","Text only","-","X"],["Misc","IE Mobile","Windows Mobile 6","-","C"],["Misc","PSP browser","PSP","-","C"],["Other browsers","All others","-","-","U"]] }
    [/code]

    Can you please tell me if I am doing anything wrong?
  • allanallan Posts: 61,609Questions: 1Answers: 10,089 Site admin
    When you access the PHP page directly, are you passing in all of the parameters that DataTables sends? If you are - then the script has an error since it is returning 57 rows, rather than 10. If you are not, then I think you might have misunderstood server-side processing.

    Have a read through the Data Sources section on this page: http://datatables.net/usage/#data_sources

    Server-side processing: Server does all the work, based on information sent to the server by DataTables.
    Ajax sourced data: Client-side processing, but the full data set is obtained from the server by a single Ajax call.

    Allan
  • phpnewbiephpnewbie Posts: 14Questions: 0Answers: 0
    Allan,
    I am not passing any parameter to the php page. I called the php page directly just to make sure that I am retrieving the data from the mysql database.

    In my client side, I am passing just
    "sAjaxSource": "server.php"

    and nothing else.

    Still, I do not see any results in my page.
  • allanallan Posts: 61,609Questions: 1Answers: 10,089 Site admin
    Okay - I think there is a little misunderstanding then. If you are not passing in any parameters, then how does the server-side script know what to get?! The fact that sEcho is 0 suggests to me that this is why no data is being presented - the first sEcho DataTables sends is 1 (it will ignore lower numbers).

    What you are using for your sever=side processing script. Something like this: http://datatables.net/development/server-side/php_mysql

    Did you read the documentation page I pointed to? Do you want server-side processing, or client-side with an Ajax data source.
  • phpnewbiephpnewbie Posts: 14Questions: 0Answers: 0
    I am php mysql.
    My PHP script is exactly the one that is mentioned at http://datatables.net/development/server-side/php_mysql

    My Client code (server_side.html)

    [code] http://pastebin.com/0d9PcDPe [/code]

    and my server.php code [code]http://pastebin.com/rvr9Ud0u[/code]

    I followed the examples and I could not find anywhere how to pass parameters from the client-side to the server-side/
  • allanallan Posts: 61,609Questions: 1Answers: 10,089 Site admin
    Hmm - there is something funny going on that I can't quite put my finger on. Can you provide a link to a live example please ( http://datatables.net/contact if you don't want to make it public). DataTables should be sending all of the data that is needed automatically as variables. Firebug might show something useful.

    Allan
  • phpnewbiephpnewbie Posts: 14Questions: 0Answers: 0
    Hi allan,

    Thanks a lot for your wonderful support.
    I installed entire datatables in my local machine, and it worked flawlessly. But when I try in the production environment, it goes kaput. Any pointers how to troubleshoot?

    Thanks
  • allanallan Posts: 61,609Questions: 1Answers: 10,089 Site admin
    Best debugging suggestion... Firebug. Does it show the XHR's going out and being processed?

    Allan
This discussion has been closed.