I am having a problem while retrieving data from mysql table making an ajax call. I am using jquery datatables to display the data. The code is as follows
var oTable;
/* Formating function for row details */
function fnFormatDetails ( nTr )
{
var aData = oTable.fnGetData( nTr );
var sOut = '<table cellpadding="5" cellspacing="0" border="0" style="padding-left:50px;">';
sOut += '<tr><td>'+aData[0]+'</td></tr>';
sOut += '</table>';
return sOut;
}
$(document).ready(function() {
oTable = $('#datatables').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "../getproducts.php",
"aData" : "POST","getproducts.php?c_name_mfac="+c_name_mfac
"aoColumns": [
{ "sClass": "center", "bSortable": false },
null,
{ "sClass": "center" },
]
} );
$('#datatables tbody tr td img').live( 'click', function () {
var nTr = this.parentNode.parentNode;
if ( this.src.match('details_close') )
{
/* This row is already open - close it */
this.src = "../images/details_open.png";
oTable.fnClose( nTr );
}
else
{
/* Open this row */
this.src = "../images/details_close.png";
oTable.fnOpen( nTr, fnFormatDetails(nTr), 'details' );
}
} );
} );
The HTML part of the code is as follows:
<div>
<table id = "datatables" class="display">
<thead>
<tr>
<th></th>
<th>Company Name</th>
</tr>
<thead>
<tbody>
<?while($row=mysql_fetch_array($result)){
<tr>
<td><img src="images/details_open.png"/></td>
<td class="center" value="c_name_mfac"><?= $row['c_name_mfac']?></td>
</tr>
<?}}?>
</tbody>
</table>
</div>
The AJAX call is made to the file getproducts.php The code is as shown below :
<?php
include('config.php');
$cname = $_POST['c_name_mfac'];
$sql = mysql_query("SELECT * FROM items where c_name_mfac = $cname ");
?>
I am not getting any syntax error but not getting the output also.
I am a beginner in AJAX and JQUERY. Basically what I need is based on a company name I need to display all its products in the jquery Datatables. I m using the DataTables hidden row details example but this dosent seem to be working for me.. Can anyone help pls.
Thanks, NC