This is the code that i get from DataTables Child Rows
$(document).ready(function() {
var table = $('#example').DataTable( {
"ajax": "../ajax/data/objects.txt", //here
"columns": [
{
"className": 'details-control',
"orderable": false,
"data": null,
"defaultContent": ''
}, //and here to fetch the data below
{ "data": "name" },
{ "data": "position" },
{ "data": "office" },
{ "data": "salary" }
],
"order": [[1, 'asc']]
} );
I would like to get the data from an SQL Query by using ajax. This is my SQL Query :
$tsql =
"SELECT *
FROM [dbo].[ITEM_MASTER] A
INNER JOIN
[dbo].[STOCK] B
ON
B.ItemId = A.ItemId
";
$result = sqlsrv_query($conn, $tsql, array(), array( "Scrollable" => SQLSRV_CURSOR_KEYSET ));
if (!$result) {
die("Query to show fields from table failed");
}
while($row=sqlsrv_fetch_array($result))
{
$ItmId = $row['ItemId'];
$ItmName = $row['ItemName'];
$ItmType = $row['ItemType'];
$ItmGroup = $row['ItemGroup'];
$ItmClass = $row['ItemClass'];
$ItmSerialNum = $row['ItemSerialNum'];
$ItmUOM = $row['ItemUOM'];
$StkQty = $row['StockQuantity'];
$StkId = $row['StockId'];
}
And on the ajax part, i just call the name of the variable like $ItmId
or like i've stated in my while loop.
Is it possible? If so, how? Since i don't have any knowledge on AJAX
UPDATE
The data were pushed to the second parameter and is not showing the ItmId
? And no matter if i change $data : ItmName
it just displays based on the arrays and display something else?
$(document).ready(function() {
var table = $('#table').DataTable( {
"ajax": {
"url": "table_data.php",
"type": "POST"
},
"columns": [
{
"class": 'details-control',
"orderable": false,
"data": null,
"defaultContent": ''
},
{ "$data": "ItmId" },
{ "$data": "ItmName" },
{ "$data": "ItmGroup"},
{ "$data": "ItmClass"}
],
"order": [[1, 'asc']]
} );