Listing Data Rows - How To

Listing Data Rows - How To

dl222xdl222x Posts: 7Questions: 0Answers: 0
edited December 2013 in General
I am using Version: 1.9.4 if that matters.

I think I am on the right track I just dont know where to go from here. I am pulling data out of a MySQL database and used the "DataTables server-side script for PHP and MySQL" example and when I visit that page it is outputing valid json, I checked. Both files are in root directory.

Here is the invocation script:

[code]

$(document).ready(function() {
$('#dyntab').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "user_list_script.php"
} );
} );

[/code]

Then here is what I have in my html (Which is a .php page if that matters).

[code]
User List











id
user_id
fname
lname









[/code]

I am just not sure how to get the data that is output from the user_list_script.php to show up in the table. I am new to jquery this is actually my first go it and I am just so lost. Any help would be greatly appreciated. I ran a debug thing and the URL for that is http://debug.datatables.net/isuhel

I would link to the page but it is on internal network that requires a login.

Replies

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395
    I don't know about "colgroup" generally, but there is a typo in its first col:

    That backward slash doesn't belong.
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    The debugger doesn't show any DataTables on the page unfortunately. So I'm sorry, but we really would need to be able to see a test case to be able to offer any help. The code you posted above looks fine, minus the error tangerine points out.

    Allan
  • dl222xdl222x Posts: 7Questions: 0Answers: 0
    What do you mean by test case? Also that is the issue I am having I don't know how to get the data into the table.

    The can be disregarded. I deleted it. I am going to post the two pages in a seperate post.
  • dl222xdl222x Posts: 7Questions: 0Answers: 0
    This is the top part of my page that I wish to have the table displayed on:

    [code]




    Accolades - User Listings | YOUR CITY Call Center



    <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>


    <![endif]-->
















    $(document).ready(function() {
    $('#dyntab').dataTable( {
    "bProcessing": true,
    "bServerSide": true,
    "sAjaxSource": "user_list_script.php" } );
    } );




    <!--[if lte IE 8]>

    <![endif]-->


    [/code]
  • dl222xdl222x Posts: 7Questions: 0Answers: 0
    This is on the same page where I want the table displayed:

    [code]




    Data Table



    id
    attuid
    fname
    lname









    [/code]
  • dl222xdl222x Posts: 7Questions: 0Answers: 0
    This is the user_list_script.php referenced as sAjaxSource.

    [code]<?php
    /*
    * Script: DataTables server-side script for PHP and MySQL
    * Copyright: 2010 - Allan Jardine
    * License: GPL v2 or BSD (3-point)
    */

    /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
    * 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( 'id', 'attuid', 'fname', 'lname');

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

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

    /* Database connection information */
    $gaSql['user'] = "USER";
    $gaSql['password'] = "PASS";
    $gaSql['db'] = "DB";
    $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
    */

    /*
    * 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 ".mysql_real_escape_string( $_GET['iDisplayStart'] ).", ".
    mysql_real_escape_string( $_GET['iDisplayLength'] );
    }


    /*
    * Ordering
    */
    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
    [/code]
  • dl222xdl222x Posts: 7Questions: 0Answers: 0
    The user_list_script.php outputs data similar to this:

    {"sEcho":0,"iTotalRecords":"353","iTotalDisplayRecords":"353","aaData":[["1","sr0000","Stephen","Ruff"],["2","ss0000","Sarah","Sol"],["3","sw0000","Stacy","White"], ["353","ls1138","Luke","Skywalker"]]}
  • dl222xdl222x Posts: 7Questions: 0Answers: 0
    My init script was not correct. Thanks for everyones input
This discussion has been closed.