Display bank data when clicking table row

0

I have a table dynamically populated when the page loads with database data, using php, everything works until then, but by clicking on a row in the table it displays in a side panel the table data plus some extras that are in the bank, how to do that?

I can already get the ID to the click on the table row.

    
asked by anonymous 18.10.2017 / 14:28

1 answer

1

Ideally you just get the ID of each record from your table and do an Ajax to get the other results. As you are already using jQuery, you would need to do an ajax on some PHP that queries those values and returns.

function getInfoById(meu_id){
  $.ajax({
    type:'GET',
    dataType: 'json',
    url: 'getDados.php',
    data: {
      id: meu_id
    }
    success: function(dados){
      $("#resultados").html("Nome: " + dados.nome + ", idade: " + dados.idade);
    }
  });
}

After receiving the ID parameter and making the query, you return the result in JSON using json_encode . By getting this information object from that single record, you can already use it to create the modal or display elsewhere quietly with jQuery, as in the example above.

Here are examples of working with Ajax and PHP together:

18.10.2017 / 18:23