2
I am making a financial system with ajax, both revenues and expenses have "descriptions" and to edit the information of a recipe I call her information but I have to pull the descriptions tbm. However, I use the front-end append to create these descriptions and I take the number of lines generated there and make a loop in php that records in the database. Now I gotta get those lines back and put that append in again.
I made it work to pull the unique data, but to pull the descriptions the way I did not working...(the description ajax is inside the "Success" of the recipe ajax for sure)
Sorry for the size of the question...
Php file that ajax calls...
<?php
include_once("../database/Database.class.php");
$database = new Database();
$idReceita = $_GET['id'];
$sql = "SELECT * FROM cnt_receita_descricao WHERE id_receita = '".$idReceita."'";
$resultado = $database->conexao->query($sql);
$linha = $resultado->fetch(PDO::FETCH_ASSOC);
$numero_de_linhas = $resultado->rowCount();
if ($numero_de_linhas > 0){
for ($i = 0; $i <$numero_de_linhas; $i++) {
  $dadoReceitaDescricao[$i] = array(
    'numero_de_linhas' => $numero_de_linhas,
    'decricao' => $linha_descricao['descricao'],
    'complemento' => $linha_descricao['complemento'],
    'valor_unitario' => $linha_descricao['valor_unitario'],
    'todos_meses' => $linha_descricao['todos_meses'],
    'numero_de_meses' => $linha_descricao['numero_de_meses']
  );
}
}
echo json_encode($dadoReceitaDescricao[$i]);
?>
Ajax script...
<script type="text/javascript">
 function pegarIdDaReceitaEditar(id){
 var idReceita = id;
 alert(idReceita);
 $.ajax({
 type: "GET",
 url: "buscarDadosReceita.php?id="+idReceita,
 success: function( response ){
   var dadosReceita = jQuery.parseJSON( response );
   $("#dadoDaReceita").val(dadosReceita.dadoDaReceita);
   // alert("teste01R-R");
   $.ajax({
     type: "GET",
     url: "buscarDadosReceitaDescricao.php?id="+idReceita,
     success: function( response ){
       var dadosReceitaDescricao = jQuery.parseJSON( response );
       $("#numero_de_linhas").val(dadosReceitaDescricao.numero_de_linhas);
       // alert("teste01R-D");
       for($i=0; $i<$dadosReceitaDescricao.numero_de_linhas; $i++){
$("#dadoDeDescricaoDaReceita"+$i).val(dadosReceitaDescricao.dadoDeDescricaoDaReceita);
       }
     }
   });
 }
 });
 }
</script>
						

Replace the source prints with text in the question.
– Sam