Strange Behavior between datatables and php

Strange Behavior between datatables and php

desidocdesidoc Posts: 13Questions: 0Answers: 0
edited September 2013 in General
Hi,

I have this problem: have 2 files ini.php and search.php

the file ini.php contains



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

THE PROBLEM is on the sql sintax, 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

Replies

  • allanallan Posts: 63,508Questions: 1Answers: 10,471 Site admin
    For PHP and SQL help, you'd be better asking on SO or similar.

    Allan
  • desidocdesidoc Posts: 13Questions: 0Answers: 0
    Hi allan,

    after a lot of test it´s not a problem of php or sql it´s from jquery and datatables, i have no experience with datatables this is mi first one.

    ¿Can you please take a look to my code and see if there´s any error in it?

    Thanks
  • allanallan Posts: 63,508Questions: 1Answers: 10,471 Site admin
    > "bServerSide": true,

    It doesn't look like your PHP script actually implements server-side processing. See: http://datatables.net/usage/server-side
  • desidocdesidoc Posts: 13Questions: 0Answers: 0
    Hi Allan,

    this is my output from the php file

    {
    "sEcho":1,
    "iTotalRecords":21,
    "iTotalDisplayRecords":1,
    "aaData":[
    [
    "dato1",
    "charla",
    "28\/09\/2013",
    "6",
    "3"
    ]
    ]
    }


    Thanks
  • desidocdesidoc Posts: 13Questions: 0Answers: 0
    ups! sorry the date format is 28/09/2013 that was an error solved
This discussion has been closed.