3
I have a questionnaire and need to pass a list with the question and the answer value, created a question table and a response table in my database, but I’m not able to pass the answer value in this list.
1. database
tabela pergunta ->
idPergunta
pergunta
resposta
tabela resposta ->
idResposta
idUsuario fk idUsuario table usuario
idQuestionario fk idQuestionario table questionario
idpergunta fk idPergunta table pergunta
valor
2. The php code is this:
<?php include ("cabecalho.php");
$result = getAllUsuarios();
while($row = mysqli_fetch_array($result)) {
?><h3><?php echo $row['nome'];?></h3>
<?php
$id = $row['idusuario'];
$resultRespostaUsuario = getRespostaByPerguntaByIdUsuario($id);
$questionario = getAllQuestionario();
while ($row2 = mysqli_fetch_array($questionario)) {
$idQuestionario = $row2['idquestionario'];
$resultPerguntaUsuario= getPerguntaByIdQuestionario($idQuestionario);
?><h4><?php echo $row2['nomeQuestionario']; ?> </h4>
<table class="table table-bordered table-striped">
<tr>
<td><a>pergunta</a></td>
<td><a>resposta</a></td>
</tr>
<?php
while($row3 = mysqli_fetch_array($resultPerguntaUsuario)){
?>
<tr>
<td><?php echo $row3['pergunta'];?></td>
<?php
while($row4 = mysqli_fetch_array($resultRespostaUsuario)) {
?>
<td><?php echo $row4['valor'];?></td>
</tr>
<?php }
}
?>
</table>
<?php }
} ?>
3. Duties:
function getAllUsuarios(){
$con = getConnection();
$sql = "select * from usuario";
return mysqli_query($con,$sql);}
function getRespostaByPerguntaByIdUsuario($id){
$con = getConnection();
$sql = "select * from resposta r
inner join questionarioPergunta qp
on qp.idpergunta = r.idpergunta where idusuario = $id";}
function getAllQuestionario(){
$con = getConnection();
$sql = "select q.*, user.nome nome from questionario q
INNER JOIN usuario user
ON q.idcriador=user.idusuario " ;
return mysqli_query($con,$sql);}
function getPerguntaByIdQuestionario($id){
$con = getConnection();
$sql = "select * from pergunta p inner join questionarioPergunta qp
on qp.idpergunta = p.idpergunta where idquestionario = $id";
return mysqli_query($con,$sql);}
What does it mean "pass the response value in this list"? The problem is here
while($row4 = mysqli_fetch_array($resultRespostaUsuario))
? What’s the mistake? Did some debug withvar_dump
? I think it is difficult to say what the problem is because you cannot reproduce your code in another system (see MCVE).– brasofilo
means I want to show you the answer the user gave on a list. and a log error [:error] [pid 1371] [client 127.0.0.1:59409] PHP Warning: mysqli_fetch_array() expects Parameter 1 to be mysqli_result, null Given in /var/www/questionario/listResposta.php on line 30, referer: http://localhost/questionario/listaRespospostaUsuario.php? idquestionario=2
– Any Karolyne Galdino
Please, [Edit]and the question to add new information.
– brasofilo
I believe it is not possible to do this way with php because it is run only once (no load of page) I will post a response...
– Silvio Andorinha