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 thewhile
?– Wallace Maxters
@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.
– Bacco
How you have the code in Javascript?
– Sergio
Wallace thank you for your comment regarding performance and best practices, but at the moment this is not my doubt.
– Roberto Albino
I am currently without any javascript to do this.
– Roberto Albino
@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.
– Wallace Maxters
I get it, I just don’t want to lose focus on the core question.
– Roberto Albino
@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.
– Bacco
I edited, for better understanding of the situation.
– Roberto Albino
@Robertoalbino where is the Javascript you have to get the value of buttons?
– Sergio
I couldn’t do it, it’s this javascript that I’m in need of help.
– Roberto Albino