1
How can I get the id of the button pressed, and the buttons are automatically generated with php and do not have your id fixed, I need the id of the button to make an SQL query with php,
Code that generates the button:
while ($linha = mysqli_fetch_array($ids))
{
$query = ("select * from componentes where id_principal = ".$linha[0]." ");
$componentes = mysqli_query($con,$query);
$resultado = mysqli_fetch_row($componentes);
$id_componente = $resultado[0];
$codigo = $resultado[2];
$nome = $resultado[3];
$entrada = $resultado[4];
$saida = $resultado[5];
$f = $resultado[6];
$m = $resultado[7];
$g = $resultado[8];
$gg = $resultado[9];
$total = ($f + $m + $g + $gg);
print "<tr>";
// ESSE É O BOTÃO QUE PRECISO PEGAR O ID QUANDO ELE SER PRESSIONADO
print "<td><button id=".$id_componente." type='submit' class='btn btn-success'>".$codigo."</td>";
Only with ajax to pass this value to php?
– Roberto Albino
directly yes, or you could use a less conventional way, create a Hidden input, fill in the value of that id and give a Submit in the form
– Felipe G.
Could I relate this Hidden input to the button that was pressed?
– Roberto Albino
$("input[name=input_test]"). val(id);
– Felipe G.
with that code within the function mentioned above you already give the id value for the input value
– Felipe G.
And do I need to create input or does this jquery code already create it? after submitting the form with post, I get the php value right : $_POST['input_teste']
– Roberto Albino
Very good your answer, congratulations.
– Roberto Albino
Exactly, you create the input and then take the value as you mentioned. Thank you, I’m happy to help!
– Felipe G.