-1
<?php
$conn = mysqli_connect('localhost', 'root', '');
if($conn){
$Selectdb = mysqli_select_db($conn, 'quiz');
}
$sql = "SELECT * FROM perguntas ORDER BY id_pergunta LIMIT 1";
$execsql = mysqli_query($conn, $sql) or die("Erro");
while($row = mysqli_fetch_array($execsql)){
# code...
$IdPergunta = $row['id_pergunta'];
$p = $row['pergunta'];
$ra = $row['respostaa'];
$rb = $row['respostab'];
$rc = $row['respostac'];
$rd = $row['respostad'];
$vp = $row['valor_pergunta'];
}
echo '<?xml version="1.0" encoding="UTF-8" ?>';
echo '<root>';
echo '<Pergunta id="IdPergunta">' . $IdPergunta . '</Pergunta>';
echo '<Pergunta id="ValorPergunta">' . $vp . '</Pergunta>';
echo '<Pergunta id="Pergunta">' . $p . '</Pergunta>';
echo '<Pergunta id="RespostaA">' . $ra . '</Pergunta>';
echo '<Pergunta id="RespostaB">' . $rb . '</Pergunta>';
echo '<Pergunta id="RespostaC">' . $rc . '</Pergunta>';
echo '<Pergunta id="RespostaD">' . $rd . '</Pergunta>';
echo '</root>';
?>
There’s no point in you taking one by one from your database. Take the maximum amount of records you want and go through the records recovered from one to one in your PHP application. The ORDER BY clause will be useful to you.
– anonimo
I’ve tried to put
"SELECT * FROM perguntas ORDER BY id_pergunta DESC"
but it’s only the first question.– João victor
Do you mean that in your database there are several records but your PHP script only shows one? Maybe because the display is being made outside the loop?
– anonimo
then select has to be inside while? But if I leave inside Lopp mysqli_query is incomplete.
– João victor
No, inside your loop you simply go assigning what you recovered from the bank but only exit the loop and display the last.
– anonimo
I did not understand the logistics, could be clearer and more detailed, I am new programming me.
– João victor