Quantcast
Channel: Últimos conteúdos
Viewing all articles
Browse latest Browse all 14190

Problemas em criar while dentro do while

$
0
0

Estou tentando criar um formulario de porguntas e respostas dinamico. Mas estou encontrando dificuldades em colocar um while dentro do outro.

 

segue abaixo o codigo caso alguém possa me ajudar ficarei muito grato

 

<?php include ("_conexao/conecta.php");?>
<?php
 $select = "SELECT * from pergunta p INNER JOIN resposta r  ON p.id_pergunta  = r.id_resposta";
    try {
        $result = $conexao->prepare($select);
        $result->execute();
        $contar = $result->rowCount();
         if($contar>0){
             while ($mostra1 = $result->FETCH(PDO::FETCH_OBJ)){    
                 ?>
                  
                    <tr>
                        <td><?php echo $mostra1->pergunta;?></td></br>
                    </tr>
                   <?php
                   $result2 = $conexao->prepare($select);
                   $result2->execute();
                   $contar2 = $result2->rowCount();
         if($contar>0){
                   while ($mostra2 = $result2->FETCH(PDO::FETCH_OBJ)){
                      
                  }
                    ?>
                    <tr>
                        <td><?php echo $mostra2->resposta;?></td></br>
                    </tr>
        <?php           
             }                 
         }
         
         }  
    } catch (PDOException $e) {
        echo $e;
    }
                
                ?>


Viewing all articles
Browse latest Browse all 14190