Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

78
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda