Jump to content

Displaying results page


sonnieboy

Recommended Posts

Can someone please help me?

 

I have a survey that collects user's name, gender and 9 questions, each question has 5 options to choose from.

 

Finally, a comments box.

 

 

I want t display these results where all respondents' answers are display on a single page.

 

I know that the page could be very long but that's ok.

 

I have the query that collects all the answers:

 

$result ="Select fullname, gender, a1,a2,a3,a4,a5,a6,a7,a8,a9, comments from survey";

 

I would like to loop through these records and then display the results in this format:

 

Name: Whatever the name

 

Gender: whatever the gender

 

Question 1: the answer

Question2: the anser

...

...

 

Comments:

 

_______________________________

 

Then the next respondent.

 

I am from the asp world and very much a noob on php

 

Your assistance in the past has been extremely useful and I beg for your assistance again, please.

 

Trust me I have searched this forum first looking for answers but have not found one yet.

 

Link to comment
https://forums.phpfreaks.com/topic/196823-displaying-results-page/
Share on other sites

Thanks a lot Mike for your response.

 

Let me ask this follow up question, please:

 

In ASP, we would do something like this:

 

 

Sqlstmt="Select fullname, gender, a1,a2,a3,a4,a5,a6,a7,a8,a9, comments from survey"

 

Set rs = conn.execute(Sqlstmt) 'Execute sql query and store results into recordset called rs.

 

WHILE NOT rs.eof

fname = rs("fullname")

sex = rs("gender")

etc

ec

rs.MoveNext

Loop

 

 

THen

 

 

    <TABLE CELLPADDING="0" CELLSPACING="0" BORDER="0" WIDTH="800">

      <TR>

        <TD><b>Respondent's Name:</b><input name="name" type="text" value="<% = fname%>"></TD>

      </TR>

      <TR>

        <TD> </TD>

      </TR>

      <TR>

        <TD><b>Respondent's Name:</b><input name="name" type="text" value="<% = sex%>"></TD>

      </TR>

      <TR>

 

ect

etc

 

 

 

 

How do I do something similar using php?

 

Again, thanks Mike

Hi again Mike or anyone, please.

 

Can you please tell me if I am on the right track?

 

This looks like what I am trying to accomplish but not real sure.

 

 

  $dbhost = 'localhost';
  $dbuser = '***************';
  $dbpass = '***************';
  $dbname = 'OnlineSurvey';
  $tableval = 'survey';

  $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to database');
  mysql_select_db($dbname);

  @mysql_select_db("$dbname") or die("Error: Unable to select database");

$query="SELECT * FROM tableval";
$result=mysql_query($query);
while($row=mysql_fetch_array($result)){
$fname=$row[fullname];
$gender=$row[gender];
$answer1=$row[answer1];
$answer2=$row[answer2];
$answer3=$row[answer3];
$answer4=$row[answer4];
$answer5=$row[answer5];
$answer6=$row[answer6];
$answer7=$row[answer7];
$answer8=$row[answer8];
$answer9=$row[answer9];
$comments=$row[comments];

  }


    <TABLE CELLPADDING="0" CELLSPACING="0" BORDER="0" WIDTH="800">
      <TR>
        <TD><b>Respondent's Name:</b>		' . $row[fullname] . '</TD>
      </TR>
      <TR>
        <TD> </TD>
      </TR>
      <TR>
        <TD><b>Respondent's Name:</b>		' . $row[gender] . '</TD>
      </TR>
      <TR>
        <TD> </TD>
      </TR>
etc
etc

This should get you started.

 

$dbhost = 'localhost';
  $dbuser = '***************';
  $dbpass = '***************';
  $dbname = 'OnlineSurvey';
  $tableval = 'survey';

  $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to database');
  mysql_select_db($dbname);

  @mysql_select_db("$dbname") or die("Error: Unable to select database");



$query="SELECT * FROM tableval";



$result=mysql_query($query);

echo '<TABLE CELLPADDING="0" CELLSPACING="0" BORDER="0" WIDTH="800">';

while($row=mysql_fetch_array($result)){
$fname=$row[fullname];
$gender=$row[gender];
$answer1=$row[answer1];
$answer2=$row[answer2];
$answer3=$row[answer3];
$answer4=$row[answer4];
$answer5=$row[answer5];
$answer6=$row[answer6];
$answer7=$row[answer7];
$answer8=$row[answer8];
$answer9=$row[answer9];
$comments=$row[comments];
echo <<<Print
      <TR>
        <TD><b>Respondent's Name:</b> {$fname}</TD>
      </TR>
      <TR>
        <TD> </TD>
      </TR>
      <TR>
        <TD><b>Respondent's Gender:</b> {$gender}</TD>
      </TR>
      <TR>
        <TD> </TD>
      </TR>
  <TR>
        <TD><b>Answers</b></TD>
      </TR>
  <TR>
        <TD><b>1</b> {$answer1}</TD>
      </TR>
  etc.
Print;
}
echo '</table>';

Thanks a lot jcbones.

 

Can I do this instead?

 

  echo <<<Print
<TABLE CELLPADDING="0" CELLSPACING="0" BORDER="0" WIDTH="800">
<tr>
<td>
...
...
</d>
</tr>
  </TABLE>
  Print;
  }

 

Basically stick the print outside of tables rather than outside of <tr>...</tr>

 

Again, thanks

Not unless you want a lot of tables.

 

while($condition) {
//this loop will run until the condition is met
//inserting tables inside this loop will create 
//a new table each time the loop runs.
}

 

BTW, <<<Print is a heredoc, and doesn't actually print to the page. http://www.phpf1.com/tutorial/php-heredoc-syntax.html

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.