using Datatables with PHP

using Datatables with PHP

urboyfriendurboyfriend Posts: 4Questions: 0Answers: 0
edited September 2011 in General
how do i load a table using PHP? im not sure where to go next

http://i172.photobucket.com/albums/w11/urboyfriend/symbols.jpg

[code]
<?PHP
$user_name = "root"; //connect to server
$password = "";
$database = "testdb";
$server = "127.0.0.1";

$db_handle = mysql_connect($server, $user_name, $password);
$db_found = mysql_select_db($database, $db_handle);



$queryString = "SELECT * FROM symbols";
$result = mysql_query($queryString);
$totalRows = mysql_num_rows($result);

for ($i = 0; $i < $totalRows; ++$i) {

$postData[$i] = mysql_fetch_array($result);

}


$myJSONString = json_encode($postData);
echo $myJSONString;

?>
[/code]

Replies

  • MrBaseball34MrBaseball34 Posts: 96Questions: 0Answers: 0
    edited September 2011
    What you want is the server-side processing. Very simple and there is example code. I have used it with PHP numerous times with success.
    http://www.datatables.net/release-datatables/examples/server_side/server_side.html
  • urboyfriendurboyfriend Posts: 4Questions: 0Answers: 0
    edited September 2011
    hello! thank you for the reply. may i get some assistance in this code? i am still using the same db,table and record that i posted above, not sure why isn't working...

    this is sample.php

    [code]




    DataTables example



    $(document).ready(function() {
    $('#example').dataTable( {
    "bProcessing": true,
    "bServerSide": true,
    "sAjaxSource": "localhost/datatableprototype/server_processing.php"
    } );
    } );





    DataTables server-side processing example







    ID
    country
    animal














    [/code]

    i have used your link above and tried to use the code, i only edited this part

    server_processing.php

    [code]

    /* Array of database columns which should be read and sent back to DataTables. Use a space where
    * you want to insert a non-database field (for example a counter or static image)
    */
    $aColumns = array( 'id', 'country', 'animal');

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

    /* DB table to use */
    $sTable = "symbols";

    /* Database connection information */
    $gaSql['user'] = "root";
    $gaSql['password'] = "";
    $gaSql['db'] = "testdb";
    $gaSql['server'] = "localhost";


    /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
    * If you just want to use the basic configuration for DataTables with PHP server-side, there is
    * no need to edit below this line
    */
    [/code]
  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    Can you provide a link? Or what is the debugger saying? What errors are you getting?
  • urboyfriendurboyfriend Posts: 4Questions: 0Answers: 0
    it doesn't display the records

    http://i172.photobucket.com/albums/w11/urboyfriend/null.jpg

    may i know what am i doing wrong? thanks!
  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    Not enough info to go on. Please view the debugger info. Read this blog for tips: http://tote-magote.blogspot.com/2011/08/debugger-basics-for-datatables.html
  • urboyfriendurboyfriend Posts: 4Questions: 0Answers: 0
    edited September 2011
    i made a screenshot of the chrome debugger

    http://i172.photobucket.com/albums/w11/urboyfriend/sp.jpg

    second one reloaded browser

    http://i172.photobucket.com/albums/w11/urboyfriend/sp2.jpg
  • GregPGregP Posts: 500Questions: 10Answers: 0
    edited September 2011
    You have bad links to both jQuery and DataTables scripts (the 404 errors) and then it is failing to call the jQuery function ($). You can even see why the links are bad (doubled up on the first part of the path).

    Simple matter of fixing your links before proceeding further.
This discussion has been closed.