I am sending an ajax to a table, but this table can only be created after receiving the value, however it is being created before in blank, how can I make a check for the table to be generated only after receiving the ajax value , stay in a loop by testing the variable to be interrupt the php code until the variable receives its correct value.
I tried this and it was not:
if (isset($_POST['IdAparelho']))
{
$query = ("select id_principal from componentes where id_secundario = ".$_POST['IdAparelho']." ");
$ids = mysqli_query($con,$query);
while ($linha = mysqli_fetch_array($ids))
{
$con = mysqli_connect("localhost","roberto","","manutencao");
$query = ("select * from componentes where id_principal = ".$linha[0]." ");
$componentes = mysqli_query($con,$query);
$resultado = mysqli_fetch_row($componentes);
$id_componente = $resultado[1];
$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);
$id_componente = $resultado[1];
$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>";
print "<td><strong>".$id_componente."</strong></td>";
print "<td><strong>".$codigo."</strong></td>";
print "<td><strong>".$nome."</strong></td>";
print "<td><strong>".$entrada."</strong></td>";
print "<td><strong>".$saida."</strong></td>";
print "<td><strong>".$f."</strong></td>";
print "<td><strong>".$m."</strong></td>";
print "<td><strong>".$g."</strong></td>";
print "<td><strong>".$gg."</strong></td>";
print "<td><strong>".$total."</strong></td>";
print "</tr>";
}
}
?>
AJAX CODE:
$(function () {
$("#visualizarAparelhos").submit(function (e) {
var index = $("#IdAparelho").attr('data-index');
e.preventDefault();
$.ajax({
type: "POST",
url: "administrador.php",
dataType: 'html',
data: {IdAparelho: index}
}).done(function (data) {
console.log(data);
});
});
});