Ordered dynamic list with search data

Asked

Viewed 312 times

0

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

<?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>';
    }
?>

This way each new search it eliminates the previous result

  • Have you considered the possibility of making asynchronous requests with AJAX?

  • So friend, I do not know very well ajax, I am starting work with php. I followed the tip of a colleague here at the forum to do with jquery or javascript, but I’m not able to think of a solution

1 answer

2


If I understand correctly, you want to go searching and keep the previous Pills, you can do it using javascript.

Let’s consider that I’m using the 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>')
   }
})

done so, whenever your ajax run it will add the resulting new, 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

  • that’s right, go searching and keep the previous searches

  • but I never saw anything ajax, could help me chat ?

  • Yes, open a chat and I’ll help you

  • beauty, I’m not getting open haha

  • How to extend this discussion to chat ?

  • https://chat.stackexchange.com/rooms/67252/lista-ajax

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.