Display database data when click table row

Asked

Viewed 253 times

0

I have a table filled dynamically when the page loads with data from the database, using php, everything works until then, but need to click on a row in the table it displays in a side panel the table data plus a few extras that are in the database, how to do this ?

I can already get the ID by clicking on the table row.

  • Enter the code of both things and how you are doing at the moment. Without code it is difficult to help

  • I guess you don’t want the page to refresh to load the data, right? So you will have to work with Ajax requests (it is a possibility) to update a div, which in turn would be just this side panel that you mentioned. In short: your Ajax request will call a PHP script that will return the data, your jQuery takes this data and populates the side panel.

1 answer

1

Ideally you just get the ID of each record of your table and do an Ajax to get the other results. Since you are already using jQuery, you would need to do an ajax in some PHP that queries these 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 doing the query, you return the JSON result using json_encode. Receiving this object of information 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 how to work with Ajax and PHP together:

Browser other questions tagged

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