Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82131

Trying to populate table from SQL database

$
0
0
I have 2 databases with several tables in them. Both of these databases are from SQL Server Management Studio 2012 Express. I am following this example: http://www.datatables.net/release-datatables/examples/server_side/server_side.html . However, I'm getting this error in a popup:

"DataTables warning (table id = 'example'): Requested unknown parameter '1' from the data source for row 0"

This is my code for the table in the .cshtml file:

<div id="allDepTable">
    <table class="display" id="example">
        <thead>
            <tr>
                <th>PRIMARY HEADINGS</th>
                <th>PRIMARY CLASS CODE</th>
                <th>PH DESCRIPTION</th>
            </tr>
	</thead>

        <tbody>
            <tr>
                <td class="dataTables_empty">Loading data from server</td>
            </tr>
        </tbody>

        <tfoot>
            <tr>
                <th>PRIMARY HEADINGS</th>
                <th>PRIMARY CLASS CODE</th>
                <th>PH DESCRIPTION</th>
            </tr>
	</tfoot>
    </table>
</div>

The .js file:

$(document).ready(function () {
    $('#example').dataTable();
});

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

The .php file:

<?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( 'Primary Headings', 'Primary Class Code', 'PH Description' );
	
	/* Indexed column (used for fast and accurate table cardinality) */
	$sIndexColumn = "Primary Class Code";
	
	/* DB table to use */
	$sTable = "ajax";
	
	/* Database connection information */
	$gaSql['user']       = "";
	$gaSql['password']   = "";
	$gaSql['db']         = "DBNAME";
	$gaSql['server']     = "DBSERVERNAME";
	
	/* 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
	 */
	
        >>>> ... Same as example file from here down
?>

My database contains 3 columns, with 14 rows. The first column contains strings, the second column contains characters, and the third column contains strings.

Thanks for the help

Viewing all articles
Browse latest Browse all 82131

Trending Articles