gedmilson 5 Denunciar post Postado Junho 26, 2015 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; } ?> mudei o codigo em parte resouvel mas está dando o seguinte resultado Como eu queria ele repete as respostas só que infelismente repete a mesma perguntas igual a quantidade de repetição das respostas. <?php include ("_conexao/conecta.php");?> <?php $select = "SELECT * from pergunta p, resposta r WHERE p.id_pergunta = r.id_perg"; try { $result = $conexao->prepare($select); $result->execute(); $contar = $result->rowCount(); if($contar>=0){ while ($mostra1 = $result->FETCH(PDO::FETCH_OBJ)){ ?> <tr> <td></br><?php echo $mostra1->pergunta;?></br></td> </tr></br> <?php $result2 = $conexao->prepare($select); $result2->execute(); $contar2 = $result2->rowCount(); if($contar2>0){ while ($mostra2 = $result2->FETCH(PDO::FETCH_OBJ)){ ?> <tr> <td><?php echo $mostra2->resposta;?></td></br> </tr> <?php } } } } } catch (PDOException $e) { echo $e; } ?> ?????????????????? Consegui resouver em partes só que agora estou precisando que o select entre no laço de repetiçao. <?php include ("_conexao/conecta.php");?> <?php $select = "SELECT * from pergunta p, resposta r WHERE p.id_pergunta = r.id_perg and p.id_pergunta <> r.id_resposta"; try { $result = $conexao->prepare($select); $result->execute(); $contar = $result->rowCount(); while ($mostra1 = $result->FETCH(PDO::FETCH_OBJ)){ ?> <tr> <td></br><?php echo $mostra1->pergunta;?></br></td> </tr></br> <?php $result2 = $conexao->prepare($select); $result2->execute(); $contar2 = $result2->rowCount(); if($contar2==$contar){ while ($mostra2 = $result2->FETCH(PDO::FETCH_OBJ)){ ?> <tr> <td><?php echo $mostra2->resposta;?></td></br> </tr> <?php $contar++;?> <?php } } } } catch (PDOException $e) { echo $e; } ?> Compartilhar este post Link para o post Compartilhar em outros sites
gedmilson 5 Denunciar post Postado Junho 26, 2015 Consegui resouver em partes só que agora estou precisando que o select entre no laço de repetiçao. <?php include ("_conexao/conecta.php");?> <?php $select = "SELECT * from pergunta p, resposta r WHERE p.id_pergunta = r.id_perg and p.id_pergunta <> r.id_resposta"; try { $result = $conexao->prepare($select); $result->execute(); $contar = $result->rowCount(); while ($mostra1 = $result->FETCH(PDO::FETCH_OBJ)){ ?> <tr> <td></br><?php echo $mostra1->pergunta;?></br></td> </tr></br> <?php $result2 = $conexao->prepare($select); $result2->execute(); $contar2 = $result2->rowCount(); if($contar2==$contar){ while ($mostra2 = $result2->FETCH(PDO::FETCH_OBJ)){ ?> <tr> <td><?php echo $mostra2->resposta;?></td></br> </tr> <?php $contar++;?> <?php } } } } catch (PDOException $e) { echo $e; } ?> Não entendi porque este post está marcado como resouvido se não consegui resouvelo ainda. Compartilhar este post Link para o post Compartilhar em outros sites