Error when generating descendant loop (family tree)

Asked

Viewed 81 times

1

This code is inside the DOMPDF script, in it I take a registered bird and Seto the variables of it in $ra, so far so good, but this system is a family tree and I must always ask the system if that bird has father and mother, if yes, shows father and mother, if not, for the loop, what is happening is that in the two other queries, If the first bird has a father and mother on record I must pay the grandfather and grandmother and maternal grandfather and grandmother and so on, what’s going on is that the ifs to know if the bird has parent and registered mother not working, if it does not have it shows, but if it has give error when generating the pdf.

The question is, how do I make the conditional if the bird has not registered the father ($Rb) and mother ($rc)?

The error is here:

$rb = isset($ra["pai"]) ? $rb["nome"] : NULL;
$rc = isset($ra["mae"]) ? $rc["nome"] : NULL;
    $cmd = db_connect()->prepare("SELECT * FROM genealogia WHERE idave = $idave");
    $cmd->execute();
    $resultado = $cmd->fetchAll(PDO::FETCH_ASSOC);

   foreach ($resultado as $ra){

if($ra['pai'] > 0){
           $selecionapai = db_connect()->prepare("SELECT * FROM genealogia WHERE idave = '".$ra['pai']."'");
           $selecionapai->execute();
           foreach($selecionapai as $rb){
               }}     

if($ra['mae'] > 0){
           $selecionamae = db_connect()->prepare("SELECT * FROM genealogia WHERE idave = '".$ra['mae']."'");
           $selecionamae->execute();
           foreach($selecionamae as $rc){
}}

$rb = isset($ra["pai"]) ? $rb["nome"] : NULL;
$rc = isset($ra["mae"]) ? $rc["nome"] : NULL;

//Criando o código HTML que será transformado em pdf
/*$dompdf->loadHtml('
<div style="width:96%; height: 965px; border: solid 3px #333; padding: 2%">
<div style="style="margin: 0 auto; width: 100%; height: 60px">
<h2">Cadastro Único de aves - CUA</h2>
</div>
'.$ra["nome"].'
'.$rb.'
'.$rc.'
<br>
</div>

');   */
       echo $ra["nome"].'<br>';
       echo $rb.'<br>';
       echo $rc.'<br>';
}
  • 3

    Always post code in text, not image.

  • I tried, but it’s a mistake, it only shows part of the code

  • I was able to add the code

  • But what’s the real question?

  • The dompdf does not generate the file if the tree (the father and mother field in the database) are registered, what I want to do is to take the mother and father of each animal, for example, animal (father | mother) (father’s father | father’s mother’s mother | mother’s mother’s father | mother’s mother’s mother’s mother) ... taking thus, the animal, Dad, Grandpa, Great-Grandpa... But the code must have some wrong conditional, because it is not generating, note that the $Rd1 and $rd2 are the paternal grandfather and paternal grandmother of $ra, for example.

  • With the information you have put there is no possibility of answer, because there is no question. @Augustovasques has already guided him and I reinforce, give a read on Stack Overflow Survival Guide in English and tries to improve your text so that someone can help you.

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.