Getting Data to Display

Getting Data to Display

gwpaulgwpaul Posts: 7Questions: 0Answers: 0
edited March 2013 in General
I just downloaded DataTables last night and I am pretty excited to see it work, but I can't seem to get my head around some things.

I have my data in mysql DB, I have set up the server_processing.php correctly, and have set the correct path. When I run my page (pagin.php) , the screen displays (a short sample)

{"sEcho":0,"iTotalRecords":"2177","iTotalDisplayRecords":"2177","aaData":[["1500000001","Jonathan","D.","Davis","U. S. Marine","34","2\/22\/2013","Kayenta","Arizona"]]}

In server_processing.php, when I comment out 'echo json_encode( $output );' and add in it's place 'echo $aRow['fname'];', the screen will display the fname column, however when trying to populate the HTML table, I am unable to get the data to display.

This is the code I have for my pagin.php

[code]
<?php
include 'server_processing.php';
//include('include/objects.php');
//include('include/jsonp.php');

$event_id = $_GET['event_id'];
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">



Untitled Document



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





<!---->



Column 1
Column 2




<?php echo $aRow['1'];?>
aoColumns[fname]


Row 2 Data 1
Row 2 Data 2




//$(document).ready(function() {
// $('#table_id').dataTable( {
// "bProcessing": true,
// "bServerSide": true,
// "sAjaxSource": "include/objects.php",
// "aoColumns": [
// { "aaData": "fname" },
// { "mDataProp": "mi" },
// { "mDataProp": "lname" },
// { "mDataProp": "occup" },
// { "mDataProp": "age" }
// ]
// } );
//} );




[/code]

This is the server_processing script

[code]
<?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('vic_id', 'fname', 'mi', 'lname','occup', 'age', 'dod', 'town','state' );

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

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

/* Database connection information */
$gaSql['user'] = "xxxxxxxx";
$gaSql['password'] = "xxxxxxxxxx";
$gaSql['db'] = "xxxxxxxxx";
$gaSql['server'] = "xxxxxxxx";

/* REMOVE THIS LINE (it just includes my SQL connection user/pass) */
//include( $_SERVER['DOCUMENT_ROOT']."/datatables/mysql.php" );


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

/*
* Local functions
*/
function fatal_error ( $sErrorMessage = '' )
{
header( $_SERVER['SERVER_PROTOCOL'] .' 500 Internal Server Error' );
die( $sErrorMessage );
}


/*
* MySQL connection
*/
if ( ! $gaSql['link'] = mysql_pconnect( $gaSql['server'], $gaSql['user'], $gaSql['password'] ) )
{
fatal_error( 'Could not open connection to server' );
}

if ( ! mysql_select_db( $gaSql['db'], $gaSql['link'] ) )
{
fatal_error( 'Could not select database ' );
}

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


/*
* Ordering
*/
$sOrder = "lname";
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]

Can someone point me in the right direction?

Thank you

Gary

Replies

  • comptech1comptech1 Posts: 3Questions: 0Answers: 0
    You shouldn't put anything inside on your HTML page. DataTables will load the data inside that tag automatically. Just specify the table headers.

    [code]



    Account
    Name
    Phone #
    Status





    [/code]
  • GregPGregP Posts: 500Questions: 10Answers: 0
    Just "plus one"ing what comptech1 said. Just the headers in the HTML.
  • gwpaulgwpaul Posts: 7Questions: 0Answers: 0
    Thank you for your reply, however I tried it and it did not work (obviously I am missing it) more important, I don't seem to understand. When you say specify table headers, how would I do that? More specifically, where in the code and I going to say that col 'fname' = First Name or "this col = this ?

    I have been searching the site and have been reading the forum for similar issues and not really finding much, so it must be really basic that I am simply missing.

    Again thank you for your reply and help.

    Gary
  • gwpaulgwpaul Posts: 7Questions: 0Answers: 0
    I guess this discussion has died. If I find the answer I will post it for future reference.

    Gary
  • allanallan Posts: 63,522Questions: 1Answers: 10,473 Site admin
    Please link to a test case so we can debug it: http://datatables.net/forums/discussion/12899/post-test-cases-when-asking-for-help-please-read

    Allan
  • gwpaulgwpaul Posts: 7Questions: 0Answers: 0
    Allan

    Thank you for your reply. I posted the code and saved it on the paged you provided, (http://live.datatables.net/igupop/edit#) however I got a blank screen, so I really don't know if you have access to it.

    My question seems pretty basic, and the code is posted above. I am using server_processing.php, which seems to be configured & pathed properly to the server/DB, I get results from the last line

    echo json_encode( $output );

    How and where do I configure that "col1 = First Column", col2 = Second Column etc...

    Is there a tutorial or instructions on the site for this? I have gone over your site and not found it.

    Again, thank you for your reply and help.

    Gary
This discussion has been closed.