Another question regarding loading records from a variable
Another question regarding loading records from a variable
ConnectionProblem
Posts: 3Questions: 0Answers: 0
I'm sorry for posting this question again, but I searched and read many threads on using fnServerData with no avail. I am trying to only load a list of patients from a specific Dr's ID. The doctor field in the patients DB is populated with the Dr's ID and the session variable that I want to use is $id.
[code]
$(document).ready(function() {
$('#example').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "removedPath"
"fnServerData": function ( sSource, aoData, fnCallback ) {
aoData.push( { "name" : "doctor", "value" : <?php $id;?> } );
$.getJSON( sSource, aoData, function (json) {
fnCallback(json);
});
},
} );
} );
[/code]
[code]// if id is specified, add it to the WHERE clause
if ( isset($_GET['doctor']) && $_GET['doctor'] != "" ) {
if ($sWhere) $sWhere .= " AND doctor=".mysql_real_escape_string( $_GET['doctor'] );
else $sWhere = " WHERE doctor=".mysql_real_escape_string( $_GET['doctor'] );
}[/code]
[code]
$(document).ready(function() {
$('#example').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "removedPath"
"fnServerData": function ( sSource, aoData, fnCallback ) {
aoData.push( { "name" : "doctor", "value" : <?php $id;?> } );
$.getJSON( sSource, aoData, function (json) {
fnCallback(json);
});
},
} );
} );
[/code]
[code]// if id is specified, add it to the WHERE clause
if ( isset($_GET['doctor']) && $_GET['doctor'] != "" ) {
if ($sWhere) $sWhere .= " AND doctor=".mysql_real_escape_string( $_GET['doctor'] );
else $sWhere = " WHERE doctor=".mysql_real_escape_string( $_GET['doctor'] );
}[/code]
This discussion has been closed.
Replies
1. To use the $_SESSION['id'] in you PHP script directly and not passing thru' aoData or
2. To get the value of the ID field using ID or Class selectors and passing it to aoData
If you are using the an inline script, you need to assign the session value to a variable and use that in aoData
[code]
var id = "<?php echo $_SESSION['id']; ?>"
[/code]
I see you are missing "echo" keyword in your assignment
[code]
aoData.push( { "name" : "doctor", "value" : "<?php echo $id; ?>" } );
[/code]
I'd suggest you use fnServerParams rather than fnServerData since it is much easier (you don't need to make your own Ajax call).
Allan
[code] "fnServerParams": function (aoData) { aoData.push({ "name": "doctor", "value": id }) },[/code]
Thanks again guys.