Grab button values that are generated randomly

Asked

Viewed 47 times

1

I need to get the values in the button click event, which are automatically generated with php. I’m not getting the job done javascript/jquery to do this.

Follow the code that generates them:

while ($i != $max)
{
  $i++;
  $con = mysqli_connect("localhost","roberto","","manutencao");
  $query = ("select id,nome from aparelhos where id = ".$i." ");
  $aparelho = mysqli_query($con,$query);
  $fetch = mysqli_fetch_row($aparelho);
  $id = $fetch[0];
  $nome = $fetch[1];
  print "<tr>";
  // IDAPARELHO É O ID QUE PRECISO PEGAR A CADA CLICK NO BOTÃO GERADO COM O FOR
  // VOU PRECISAR ENVIAR ESSE ID PARA O PHP FAZER UMA CONSULTA NO BANCO DE DADOS
  //
  print "<td><button id='IdAparelho' value='".$id."' type='submit' class='btn btn-primary' data-toggle='modal' data-target='#modalVisualizarComponentes' data-index='".$id."' >".$id."</button></td>";
  print "<td><strong>".$nome."</strong></td>";
  print "</tr>";
}
  • You really need to repeat the mysql_connect? within the while?

  • @Wallacemaxters not only do not need, but normally should not :) - in a joke like this the application consumes all the connection links available on the server.

  • How you have the code in Javascript?

  • Wallace thank you for your comment regarding performance and best practices, but at the moment this is not my doubt.

  • I am currently without any javascript to do this.

  • 1

    @Robertoalbino is not about performance or good practice. If you want, we can help you with your problem, but much more than that, wanting people to learn to do it the right way, and not just plug the hole with a half-assed solution.

  • I get it, I just don’t want to lose focus on the core question.

  • @Robertoalbino try [Dit] and put more details beyond the code, it is difficult to understand the problem in fact and what you want to do exactly. What values are you talking about, how you’re gonna use it, etc.

  • I edited, for better understanding of the situation.

  • @Robertoalbino where is the Javascript you have to get the value of buttons?

  • I couldn’t do it, it’s this javascript that I’m in need of help.

Show 6 more comments
No answers

Browser other questions tagged

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