0
Good night, I need to ask a question system (a question) just like this: https://jsfiddle.net/hmana2sL/
I just need the questions and the answer options to come from the bank. I tried this way only that the radios are coming out empty, the more the query this ok, and running it in Mysql returns the data correctly, think it might be something with the loops, someone could help me find the error?:
Follows code:
<?php
//CONEXÃO
$servername = "127.0.0.1"; $username = "root"; $password = "root"; $dbname = "master";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
//CONEXÃO
$QPergunta = "SELECT sug_perg_id AS ID_PERGUNTA, sug_perg_pergunta AS PERGUNTA FROM sugestoes_perguntas WHERE sug_perg_area = 3";
$QAvalicao = "SELECT sug_aval_id AS ID_AVALIACAO, sug_aval_desc AS DESCRICAO FROM sugestoes_avaliacao";
$RPergunta = $conn->query($QPergunta);
$RAvaliacao = $conn->query($sql);
while($row = $RPergunta->fetch_assoc()){
echo "PERGUNTA :".$row["PERGUNTA"];
echo"<br>";
while($row = $RAvaliacao->fetch_assoc()){
echo"<input type='radio' name='".$row["ID_PERGUNTA"]."' value='".$row["ID_AVALIACAO"]."'>".$row["DESCRICAO"];
echo"<br>";
}
}
//FINALIZA CONEXÃO
$conn->close();
//FINALIZA CONEXÃO
?>
Why is this possibly going to solve the problem? Note that Sopt is not a support system, but a community for professional programmers and enthusiasts. The main goal is to create quality content that serves as a reference. A code-only answer goes far beyond that, so please edit your answer explaining what was wrong in the question code and what solution was adopted, if it is the only solution, if it is the best solution, why it is the best, etc. In fact, why a
while
empty to create the answer list? This seems completely unnecessary.– Woss
Okay, thank you, editing...
– Victor Laureano
@Andersoncarloswoss Edited, and explained why the while "empty". Kisses.
– Victor Laureano
Much better. Take this as a standard for future responses. By the way, the
while
remains empty. The fact that the condition performs something does not change the fact that it is empty. Remembering that emptiness is not the same as "doing nothing". For this case, you can use the functionmysqli_fetch_all
, that is optimized internally.– Woss