Trying to populate table from SQL database
Trying to populate table from SQL database
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:
[code]
PRIMARY HEADINGS
PRIMARY CLASS CODE
PH DESCRIPTION
Loading data from server
PRIMARY HEADINGS
PRIMARY CLASS CODE
PH DESCRIPTION
[/code]
The .js file:
[code]
$(document).ready(function () {
$('#example').dataTable();
});
$(document).ready(function() {
$('#example').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "scripts/server_processing.php"
} );
} );
[/code]
The .php file:
[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( '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
?>
[/code]
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
"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:
[code]
PRIMARY HEADINGS
PRIMARY CLASS CODE
PH DESCRIPTION
Loading data from server
PRIMARY HEADINGS
PRIMARY CLASS CODE
PH DESCRIPTION
[/code]
The .js file:
[code]
$(document).ready(function () {
$('#example').dataTable();
});
$(document).ready(function() {
$('#example').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "scripts/server_processing.php"
} );
} );
[/code]
The .php file:
[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( '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
?>
[/code]
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
This discussion has been closed.
Replies
[code]
$(document).ready(function () {
$('#example').dataTable();
});
[/code]
Because it was a repeat of the lines below it. I also changed, "$sTable = "ajax";" in the .php file to "$sTable = "DBTABLENAME";" (I've replaced DBTABLENAME with the name of the table in the database that I want to use). However, I am still having trouble connecting to my database. When I try to access the .php file after I load the page, I get a, "Could not open connection to server" error. I don't think I have a username/password to the database, which is why I left those sections blank.
If it helps anyone, I am making the site using Webmatrix 3. I have added the database connections already
Can someone please help me figure this out? Thanks