Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

83
Visualizações
Displaying PHP search results on screen

I have complied a php search page but i am having trouble working out a page display issue that i would like to have.

My data return query is correct and i believe my issue is how i display the information on screen.

Example table

userid    Questionnaire ID      QID     Question        Answer 
  1        38                   846     Question 1      Answer 1
  1        38                   849     Question 2      Answer 2
  1        38                   850     Question 3      Answer 3
  1        38                   869     Question 4      Answer 4
  2        38                   846     Question 1      Answer 1
  2        38                   849     Question 2      Answer 2
  2        38                   850     Question 3      Answer 3
  2        38                   869     Question 4      Answer 4

what i would like to display

userid
1
Questionaire ID
38
Question 1
Answer 1
Question 2
Answer 2
Question 3
Answer 3
Question 4
Answer 4
PAGE BREAK (if possible)
userid
2
Questionaire ID
38
Question 1
Answer 1
Question 2
Answer 2
Question 3
Answer 3
Question 4
Answer 4

What I am getting is this

userid
1
Questionaire ID
38
Question 1
Answer 1
userid
1
Questionaire ID
38
Question 2
Answer 2
userid
1
Questionaire ID
38
Question 3 etc


userid
2
Questionaire ID
38
Question 1
Answer 1
userid
2
Questionaire ID
38
Question 2
Answer 2
userid
2
Questionaire ID
38
Question 3 etc

I believe I have to use an array with foreach from doing my searches on the internet but i am new to PHP and self teaching so find it difficult to understand the way it works. This is how i echo my results

while ($row = pg_fetch_array($result)) {


echo '<div style="border:1px solid #000000; padding:15px; margin-bottom: 10px;">';
echo '<p><strong>User ID:</strong><br> ' . $row['userid'] . '</p>';
echo '<p><strong>Questionaire ID:</strong><br> ' . $row['Questionaire ID'] . '</p>';
echo '<p><strong>Question:</strong><br> ' . $row['Question'] . '</p>';
echo '<p><strong>Answer:</strong><br> ' . $row['Answer'] . '</p>';
echo '</div>';

Sorry i updated my post to be alittle clearer

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Store the results in an array and then print them to the screen.

//I have never seen pg_fetch_array()
while($row = mysql_fetch_assoc($result)){
  $new_arr[] = $row;
}
//print each row
foreach($new_arr as $new){
  echo $new;
}
over 4 years ago · Santiago Trujillo Relatório

0

Try it

<table>
  <tr>
    <th>userid</th>
    <th>Questionnaire ID</th>
    <th>QID</th>
    <th>Question</th>
    <th>Answer</th>
  </tr>
  <?php
    while ($row = pg_fetch_array($result)) {
     echo '<tr>';
     echo '<th>'.$row['userid'].'</th>';
     echo '<th>'.$row['Questionaire ID'].'</th>';
     echo '<th>'.$row['QID'].'</th>';
     echo '<th>'.$row['Question'].'</th>';
     echo '<th>'.$row['Answer'].'</th>';
     echo '</tr>'
    ?>
</table>
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda