-4
I am sending an ajax to a table, but this table can only be created after receiving the value, but it is being created before in white, as I can make a check for the table to be generated only after receiving the ajax value, stay in a loop testing the variable to interrupt the php code until the variable receives its correct value.
I tried that and it wasn’t:
 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);
    }); 
    });
    });
Please show the code of the table creation.
– Cesar Augusto
I edited the post
– Roberto Albino
This is being sent using Ajax:
$_POST['IdAparelho']? If yes, you have already checked if there is any value within this variable?– Cesar Augusto
I checked yes, the problem is that the variable only ceases to be null, after the table has already been created.
– Roberto Albino
Roberto, in your javascript function put a
console.log(index)to see if this variable has any value before sending it to php.– Cesar Augusto
I did the test, it is passing the value 1.
– Roberto Albino
Let’s go continue this discussion in chat.
– Cesar Augusto