sonnieboy Posted March 28, 2010 Share Posted March 28, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/196823-displaying-results-page/ Share on other sites More sharing options...
dmikester1 Posted March 28, 2010 Share Posted March 28, 2010 $result = mysql_query($query); while($row = msyql_assoc_array($result) { echo "Name: " . $row['fullname']; echo "Gender: " . $row['gender']; etc.... } Something like that should get you started. Mike Quote Link to comment https://forums.phpfreaks.com/topic/196823-displaying-results-page/#findComment-1033266 Share on other sites More sharing options...
sonnieboy Posted March 29, 2010 Author Share Posted March 29, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/196823-displaying-results-page/#findComment-1033295 Share on other sites More sharing options...
sonnieboy Posted March 29, 2010 Author Share Posted March 29, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/196823-displaying-results-page/#findComment-1033310 Share on other sites More sharing options...
jcbones Posted March 29, 2010 Share Posted March 29, 2010 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>'; Quote Link to comment https://forums.phpfreaks.com/topic/196823-displaying-results-page/#findComment-1033317 Share on other sites More sharing options...
sonnieboy Posted March 29, 2010 Author Share Posted March 29, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/196823-displaying-results-page/#findComment-1033324 Share on other sites More sharing options...
jcbones Posted March 29, 2010 Share Posted March 29, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/196823-displaying-results-page/#findComment-1033333 Share on other sites More sharing options...
sonnieboy Posted March 29, 2010 Author Share Posted March 29, 2010 ok, got it. many thanks Quote Link to comment https://forums.phpfreaks.com/topic/196823-displaying-results-page/#findComment-1033338 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.