Struggling getting Table data

Struggling getting Table data

cragusscraguss Posts: 8Questions: 0Answers: 0
edited March 2012 in General
Hi, I know i'm a newbie and need my hand holding with this, but I am struggling getting the datatables working.

$("#table").dataTable(); - I presume #table is pulling in the require data from a pre-defined table.

I know how to use PHP to return data from a SQL database, and I can get this to show on a php page. However I want to input the table that I have aquired using PHP into the Java definition above. I just have no idea how to do this, can anybody help?

Replies

  • hybrishybris Posts: 5Questions: 0Answers: 0
    Hi Craguss, your server should be return data in JSON format (well formatted).
    To do this, your script should return data in json, you can use json_encode(yourArrayDataFromDb).
    Better you set the header too to "application/json".

    Then you can call the script via ajax.
    You can read docs about sAjaxSource, sAjaxDataProp and http://datatables.net/release-datatables/examples/data_sources/server_side.html
  • cragusscraguss Posts: 8Questions: 0Answers: 0
    Thanks hybris,
    I have decided to try and use this code to pull the data from SQL db,


    $(document).ready(function() {
    $("#test").dataTable();
    "bProcessing": true,
    "bServerSide": true,
    "sAjaxSource": "../pbn/media/js/server_processing.php"


    I have set the server_processing.php to use my SQL db, and I copied the PHP from this site http://datatables.net/release-datatables/examples/data_sources/server_side.html

    But I get no table, am I missing something with the HTML code???
  • hybrishybris Posts: 5Questions: 0Answers: 0
    edited March 2012
    try to leave for a moment the results data from sql.

    let the script returns an array like this:

    $array["aaData"][] = array('Trident', 'Internet Explorer 4.0', 'Win 95+', 4, 'X');
    $array["aaData"][] = array('Trident', 'Internet Explorer 5.0', 'Win 95+', 4, 'X');
    $array["aaData"][] = array('Trident', 'Internet Explorer 6.0', 'Win 95+', 4, 'X');
    return $array;

    then call it from DataTables.

    if it is all right, then you can think how to decode your results from db.
    notice: if you want put in the array "name column"=>"value", then you should map the columns in DataTables.

    The solution many time is in the server side. The first e most important step is to give to DataTables the rights data format :)
  • cragusscraguss Posts: 8Questions: 0Answers: 0
    Sorted. Thanks
This discussion has been closed.