Hi,
I have this problem: have 2 files ini.php and search.php
the file ini.php contains
<select name="Combobox1" onchange= "MostrarResultados()" id="Combobox1" style="width:120px"></select>
function MostrarResultados(){
cate= $("#Combobox1").val();
$.ajax({
type: 'POST',
url: 'search.php',
data:{datos:cate},
success: function(data) {
alert("Data Loaded: " + data); // to see if i get back data form search.php
var oTable = $("#dataTable").dataTable();
oTable.fnClearTable();
oTable.fnDestroy();
$('#dataTable').dataTable( {,
"bServerSide": true,
"sAjaxSource": "../search.php",
"oLanguage": {
"sLengthMenu": "Mostrar _MENU_ Registros por página",
"sZeroRecords": "No se encontró nada",
"sInfo": "Mostrando del _START_ al _END_ de _TOTAL_ Registros",
"sInfoEmpty": "Mostrando del 0 al 0 de 0 Registros",
"sInfoFiltered": "(Filtrado de un total de _MAX_ Registros)"
},
"aLengthMenu": [[5, 10, 15, -1], [5, 10, 15, "Todo"]]
});
$("#dataTable_previous").html("Anterior");
$("#dataTable_next").html("Siguiente");
$("#dataTable_filter label").contents().first().remove();
$("#dataTable_filter label input").attr('placeholder', 'Buscar');
}
});
}
On the other hand my search.php contains
<?php
include ('Conex.php');
$datareceived=$_POST['datos'];
$sql = mysqli_query($conex,"SELECT a.description as Description, a.idcategoria as idcategoria FROM categoria a WHERE Active = 'S' AND a.idcategoria = '$datareceived' ");
$aColumns = array( 'Description', 'idcategoria');
$output = array(
"aaData" => array()
);
while ($registro = mysqli_fetch_array($sql))
{
$row = array();
for ( $i=0 ; $i<count($aColumns) ; $i++ )
{
switch ( $aColumns[$i]){
case "Description":
$row[] = $registro[ $aColumns[$i] ] ;
break;
default:
$row[] = $registro[ $aColumns[$i] ];
}
}
$output['aaData'][] = $row;
}
mysqli_free_result($sql);
echo json_encode( $output );
?>
THE PROBLEM is on the sql sintax and datatables, if i do a.idcategoria = '$datareceived' it doesn't show data on the datatable, although it gives back the data because i can see it in an alert on ini.php.
If i do a.idcategoria = 22 it works perfect, fills the datatable
I compare the output in the two cases with DiffMerge and it's the same in both.
Can anyone please help me, i don´t have any idea of what's happening here and i'm new with this pluging
Thanks