Need help with passing DataTables a variable
Need help with passing DataTables a variable
Hello everybody I am new to not only DataTables and JQuery as well. I have a drop down on my web page that is populated by the database. The onchange event calles a javascript function and passes to the function the value of the selected option from the drop down. This value will then be used in the query that DataSource.php uses to return all the data. Here is the code so you can see what I am talking about.
Drop Down:
<?PHP
$sql="SELECT * FROM semester";
$result=mysql_query($sql, $conn) or Die ("Failed to retrieve semester list");
$count=mysql_num_rows($result);
if(isset($_GET['semester'])){
$semester_id=$_GET['semester'];
}
echo "";
echo "--Select A Semester--";
while($record=mysql_fetch_array($result, MYSQL_NUM)){
if ($semester_id == $record[0]){
echo "$record[1]";
}else{
echo "$record[1]";
}
}
echo "";
?>
Print Table Function:
function printTable(semesterID){
//alert(semesterID);
$(document).ready(function() {
$('#dataTable').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "./dataSource.php?semester="+semesterID;
} );
} );
}
You will notice that I am appending the variable to the datasource. I have a $_GET in the datasource.php file to get the variable and use it as a parameter but it does not work. Does anybody have any idea how i can make this work?
Drop Down:
<?PHP
$sql="SELECT * FROM semester";
$result=mysql_query($sql, $conn) or Die ("Failed to retrieve semester list");
$count=mysql_num_rows($result);
if(isset($_GET['semester'])){
$semester_id=$_GET['semester'];
}
echo "";
echo "--Select A Semester--";
while($record=mysql_fetch_array($result, MYSQL_NUM)){
if ($semester_id == $record[0]){
echo "$record[1]";
}else{
echo "$record[1]";
}
}
echo "";
?>
Print Table Function:
function printTable(semesterID){
//alert(semesterID);
$(document).ready(function() {
$('#dataTable').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "./dataSource.php?semester="+semesterID;
} );
} );
}
You will notice that I am appending the variable to the datasource. I have a $_GET in the datasource.php file to get the variable and use it as a parameter but it does not work. Does anybody have any idea how i can make this work?
This discussion has been closed.
Replies
So I got it to work with the dropdown however now when we switch between semesters we get the following error...
"DataTables warning: Unable to re-initialise DataTable. Please use the API to make any configuration changes required."
Anybody have any idea on how to fix this?
Allan