Dynamic list ordered with search data

0

I have a problem to display data coming from a database in an orderly way, I have a field for the user to enter with the ID and it returns the user name, and when it is looking for more users the previous ones should hold.

<?php
    $a = $_GET['a'];
    if($a == "buscar"){
        $id = $_POST['id'];
        $sql = ibase_query("SELECT NOME FROM TB_CLIENTE WHERE ID_CLIENTE = $id ");
        $row = ibase_fetch_row($sql);
        echo '<tr>';
        echo '<td>' . $row[0] . '</td>';
        echo '</tr>';
    }
?>

In this way each new search it eliminates the previous result

    
asked by anonymous 17.10.2017 / 20:04

1 answer

2

If you understand correctly, you want to go looking for and maintain the previous bucas, you can do this using javascript .

Let's take into account that I'm using jquery

// Estrutura HTML

    <ul id="lista"></div>


// Estrutura JS
$.ajax({
   url: 'SUA URL',
   data: {
      id: // ID PASSADO
   },
   success: function(data){
      $('#lista').append('<li>'+data.nome+'</li>')
   }
})

This is done, whenever your ajax is executed it will add the new resulting, keeping the previous.

<?php
    $a = $_GET['a'];
    $retorno = array();
    if($a == "buscar"){
        $id = $_POST['id'];
        $sql = ibase_query("SELECT NOME FROM TB_CLIENTE WHERE ID_CLIENTE = $id ");
        $row = ibase_fetch_row($sql);
        $retorno['nome'] = $row[0];
    }

   die(json_encode($retorno));
?>

This is a superficial example, just adapt

    
17.10.2017 / 20:12