PHP source

PHP source

lvalerolvalero Posts: 13Questions: 0Answers: 0
edited January 2010 in General
Hello,

I did not succeed in injecting php output to my table, here is the page :
http://www.polymtl.ca/gch/Outils/nouvelles/gestion/table.html

the non working part :
$('#example2').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": 'fill_table.php'
} );


fill_table.php outputs :
http://www.polymtl.ca/gch/Outils/nouvelles/gestion/fill_table.php

It is based on the example, but it cannot have it worked.

PHP 5, jquery 1.3

Replies

  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin
    Hi lvalero,

    Looks like you've got it working now. Everything okay?

    Btw - DataTables 1.6.0 has updated images for the sorting which are png8 files with transparency. This will help integration with background colours other than white.

    Regards,
    Allan
  • lvalerolvalero Posts: 13Questions: 0Answers: 0
    edited January 2010
    Hello,

    Actually, here is what i did, i removed the : bServerSide

    [code]
    $('#example2').dataTable( {
    "bProcessing": true,
    //"bServerSide": true,
    "sAjaxSource": 'fill_table.php'
    } );
    [/code]

    and did my own json Output, fill_table.php :
    [code]
    <?php
    include_once 'connect_mysql.php';
    $output = '';
    $a = mysql_query("DELETE FROM jsonlist");
    // libre
    $b = mysql_query("INSERT INTO jsonlist SELECT nouvelle.idnouvelle, nouvelle.type, LEFT(libre.titre, 30), nouvelle.date, nouvelle.etat FROM nouvelle, libre WHERE nouvelle.idnouvelle = libre.idlibre");
    // doct_mait
    $c = mysql_query("INSERT INTO jsonlist SELECT nouvelle.idnouvelle, nouvelle.type, CONCAT(LEFT(doct_mait.titre, 30),doct_mait.candidat), nouvelle.date, nouvelle.etat FROM nouvelle, doct_mait WHERE nouvelle.idnouvelle = doct_mait.iddoct_mait");

    $result = mysql_query("SELECT id, type, titre, date, etat FROM jsonlist ORDER BY date");
    $output .= '{ "aaData": [';
    while ($row = mysql_fetch_object($result)) {
    //print json_encode($row);
    //$arr[] = $row;
    $output .= '["'.$row->id.'","'.$row->type.'","'.utf8_encode($row->titre).'","'.$row->date.'","'.$row->etat.'"],';
    }
    $output = substr_replace($output ,"",-1);
    $output .= '] }';
    echo $output;
    mysql_free_result($result);
    ?>
    [/code]

    It works but now it is a php json feed ajax, the structure is different from your example (the beginning) :
    [code]{"sEcho": 0, "iTotalRecords": 57, "iTotalDisplayRecords": 57, "aaData": [ ["1","Trident"...[/code]

    Best Regards.
  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin
    Without bServerSide:true, then you don't need to return iTotalRecords etc - since all the sorting / filtering etc is done on the client side. See these two pages for the difference:

    http://datatables.net/examples/data_sources/ajax.html
    http://datatables.net/examples/data_sources/server_side.html

    Regards,
    Allan
This discussion has been closed.