Send AJAX to a table

0

I have a database page inserted in a table:

<div class="procurar">
    <input type="text" id="search" onkeypress="mandar()"><i class="fa fa-search" aria-hidden="true"></i>
</div>

<div class="historico">

<table class="table" id="dados_entradas">

<?
    $historico = mysql_query("SELECT ut.nome, ut.contribuinte, en.id_ficha, DATE_FORMAT(en.data_entrada,'%d-%m-%Y') as data
                              FROM entrada en,utilizador ut
                              WHERE en.contribuinte = ut.contribuinte");

    while($linhas = mysql_fetch_array($historico))
    {
?>
    <tr>
        <td style="width:25%;"><?echo $linhas['nome']; ?></td>
        <td style="width:25%;"><?echo $linhas['contribuinte']; ?> </td>
        <td style="width:25%;"><?echo $linhas['id_ficha']; ?> </td>
        <td style="width:25%;"><?echo $linhas['data']; ?></td>
    </tr>

<?  
    }
?>

</table>    

And then I made an input with onkeypress to send a query in AJAX, to send to this same table.

AJAX

    function mandar()
{
    var search=$("#search").val();

    $.post("dados-entradas.php",{search:search}, function(data){
        $("#dados_entradas").html(data);

});
}

And on page dados-entradas.php

$search = $_POST['search'];

    $historico = mysql_query("SELECT ut.nome, ut.contribuinte, en.id_ficha, DATE_FORMAT(en.data_entrada,'%d-%m-%Y') as data
                              FROM entrada en,utilizador ut
                              WHERE en.contribuinte = ut.contribuinte
                              AND ut.nome = '$search'");

    while($linhas = mysql_fetch_array($historico))
    {

    echo"<table class='table' id='dados_entradas'>  
    <tr>
        <td style='width:25%;'>".$linhas['nome']."</td>
        <td style='width:25%;'>".$linhas['contribuinte']."</td>
        <td style='width:25%;'>".$linhas['id_ficha']."</td>
        <td style='width:25%;'>".$linhas['data']."</td>
    </tr>
    </table>";


    }

The problem is that it does not return any value, and it defaces the entire homepage except the table.

    
asked by anonymous 03.05.2016 / 18:07

1 answer

2

Notice the following, you declare the table as follows:

<table class="table" id="dados_entradas">

However, in the data-entry.php page you declare the above line again, when you should declare only the tr's.

This is the first situation. I noticed that in your sql, you put to search by exact match:

ut.nome = '$search'

When could it be:

ut.nome LIKE '%" . $search . "%'
    
03.05.2016 / 18:16