Need help using DataTables with MySql database

Need help using DataTables with MySql database

Chiqui7988Chiqui7988 Posts: 13Questions: 0Answers: 0
edited December 2013 in General
Hi. I am trying to use DataTables with "localhost", "myDatabase", "myUser" and "mypass" and I can´t get it. PLEASE, can you help me with an example? Thanks a lot from now. Oh, and Merry Christmas for all of you.

Replies

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395
    You will have to provide more detail. How far have you got? What does your code look like?
  • Chiqui7988Chiqui7988 Posts: 13Questions: 0Answers: 0
    Please, forgive my mistake: here is my code (as you can see, I took it from the example)
    Thanks a lot!!!
    Ruben

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">





    DataTables example




    $(document).ready(function() {
    $('#example').dataTable( {
    "bProcessing": true,
    "bServerSide": true,
    "sAjaxSource": "../server_side/scripts/delservi.php"
    } );
    } );








    Usuario
    Nivel
    dirección




    usuario
    nivel
    direccion





    usuario
    nivel
    la direc













    ... and server side

    <?php
    /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
    * Easy set variables
    */

    /* 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( 'usuario', 'nivel', 'direccion' );

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

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

    /* Database connection information */
    $gaSql['user'] = "usuario";
    $gaSql['password'] = "micontra";
    $gaSql['db'] = "mibase";
    $gaSql['server'] = "localhost";

    /* REMOVE THIS LINE (it just includes my SQL connection user/pass) */


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

    /*
    * MySQL connection
    */
    $gaSql['link'] = mysql_pconnect( $gaSql['server'], $gaSql['user'], $gaSql['password'] ) or
    die( 'Could not open connection to server' );

    mysql_select_db( $gaSql['db'], $gaSql['link'] ) or
    die( 'Could not select database '. $gaSql['db'] );


    /*
    * Paging
    */
    $sLimit = "";
    if ( isset( $_GET['iDisplayStart'] ) && $_GET['iDisplayLength'] != '-1' )
    {
    $sLimit = "LIMIT ".intval( $_GET['iDisplayStart'] ).", ".
    intval( $_GET['iDisplayLength'] );
    }


    /*
    * Ordering
    */
    $sOrder = "";
    if ( isset( $_GET['iSortCol_0'] ) )
    {
    $sOrder = "ORDER BY ";
    for ( $i=0 ; $i $iFilteredTotal,
    "aaData" => array()
    );

    while ( $aRow = mysql_fetch_array( $rResult ) )
    {
    $row = array();
    for ( $i=0 ; $i
  • Chiqui7988Chiqui7988 Posts: 13Questions: 0Answers: 0
    I tried to put my code, I am not sure I get it

    Server side
    /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
    * Easy set variables
    */

    /* 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( 'usuario', 'nivel', 'direccion' );

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

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

    /* Database connection information */
    $gaSql['user'] = "usuario";
    $gaSql['password'] = "micontra";
    $gaSql['db'] = "mibase";
    $gaSql['server'] = "localhost";

    /* REMOVE THIS LINE (it just includes my SQL connection user/pass) */


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

    /*
    * MySQL connection
    */
    $gaSql['link'] = mysql_pconnect( $gaSql['server'], $gaSql['user'], $gaSql['password'] ) or
    die( 'Could not open connection to server' );

    mysql_select_db( $gaSql['db'], $gaSql['link'] ) or
    die( 'Could not select database '. $gaSql['db'] );

    etc....
  • Chiqui7988Chiqui7988 Posts: 13Questions: 0Answers: 0
    \\10.32.23.95\exampledatatable here are my files
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    You page doesn't appear to be loading for me at the moment. Browser says that the server is not reachable.

    Allan
  • Chiqui7988Chiqui7988 Posts: 13Questions: 0Answers: 0
    I solved the problem! ( am so silly :( there was a problem with a path). Thanks a lot!!!! and MERRY CHRISTMAS!!
This discussion has been closed.