Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 165
  • Last Modified:

Survey Results Quick Question

I have the following Survey with the followign DB:

Questions Table is TblSurveyQuestions: QuestionID, Survey Question
Answers Table is TblSurveyAnswers: AnswerID, ChoiceText, Question, ChoiceOrder

Now I have a query on the page that displays the info as such

<cfquery name="Survey" datasource="#DB#">
SELECT TblSurveyQuestions.QuestionID, TblSurveyQuestions.SurveyQuestion,
TblSurveyAnswers.AnswerID, TblSurveyAnswers.Question, TblSurveyAnswers.ChoiceText, TblSurveyAnswers.ChoiceOrder
FROM TblSurveyQuestions, TblSurveyAnswers
WHERE TblSurveyQuestions.QuestionID=TblSurveyAnswers.Question
ORDER By ChoiceOrder
</cfquery>

<cfform name="survey" method="post" action="SurveyDetails.cfm">
<cfinput name="Answer" type="radio" value="#Survey.AnswerID#" required="yes" message="Please Select a Choice">

<input name="submit" type="submit" class="SurveyButton" value="Continue">
</cfform>

I just want to output the results on how many times a choice has been selected. So i will have it on a separate page.

So all i wanna do is output the following for example:
Question:Hey how are you
AnswerID:5
AnswerID:10
AnswerID:15
AnswerID:50

On the details page here is teh query that I have:

<!--- Querying the News Details Page Based on the Form Value Passed --->
<cfquery name="SurveyDetails" datasource="#DB#">
SELECT * FROM TblSurveyAnswers WHERE ID = #FORM.Answer#
</cfquery>

Thanks a gain for all your help,
ISM
0
ISM
Asked:
ISM
  • 2
1 Solution
 
danrosenthalCommented:
try this...

SELECT AnswerID, count(1) AS num_answers
FROM TblSurveyAnswers
WHERE Question = #questionID#
GROUP BY AnswerID

0
 
substandCommented:
<cfquery name="Survey" datasource="#DB#">
SELECT TblSurveyQuestions.QuestionID, TblSurveyQuestions.SurveyQuestion
FROM TblSurveyQuestions, TblSurveyAnswers
WHERE TblSurveyQuestions.QuestionID=TblSurveyAnswers.Question
ORDER By TblSurveyQuestions.QuestionID
</cfquery>

<cfoutput query="survey">
<cfquery name="answers" datasource="#DB#">
select TblSurveyAnswers.AnswerID, TblSurveyAnswers.Question, TblSurveyAnswers.ChoiceText, TblSurveyAnswers.ChoiceOrder
where TblSurveyAnswers.Question=#questioID#;
ORDER By ChoiceOrder
</cfquery>
#surveyQuestion#<br>
<cfloop query=answers>
#answers.answerID# #answers.ChoiceText#<br>
</cfloop>
</cfoutput>
-----------------------------------------------------------
that will output the questions and answers.  but where are your recorded responses?  you cant get anywwhere without them.
0
 
ISMAuthor Commented:
Ok, I have tried both ways and I keep getting number 11 all the time whatever I do and I am passing the question ID as a hidden form variable becauase I don't have it that query as you see from my code above. There are two sepaerate tables one for questins and one for answers.

If I can onyl output the results like that:

Quetion 1 is pulling form the questions table an dhave four choices in the answers table:

How are you doing today:

Answers and results:
I am doing fine (ChoiceText in the AnswerTable): 45 times slected or answered
Not too bad (ChoiceText in the AnswerTable): 20 times selected and so on
Alright(ChoiceText in the AnswerTable):
Cool(ChoiceText in the AnswerTable):

<cfquery name="SurveyDetails" datasource="#Application.Datasource#">
SELECT AnswerID, count(1) AS num_answers
FROM TblSurveyAnswers
WHERE Question = #Form.question#
GROUP BY AnswerID
</cfquery>

<html>
<head>
<title><cfoutput>#Application.Title#</cfoutput></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="Styles.css" rel="stylesheet" type="text/css">
</head>

<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="493" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="493" height="444" valign="middle" background="images/NewsBg.gif">
      <blockquote class="NewsDetailTitle">&nbsp;</blockquote>
      <blockquote class="Copy">
        <p>&nbsp;</p>
        <br>
        <table width="425" border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td width="42" valign="top">&nbsp;</td>
            <td width="383" valign="top"><p class="NewsDetailTitle">
               <cfoutput>#SurveyDetails.AnswerID#</cfoutput><br>
                <br>
              </p>
              <p align="right">
                <input name="button" type="button" class="SearchButton" onClick="javascript:window.close()" value="Close">
              </p></td>
          </tr>
        </table>
        <p>&nbsp;</p>
        <p>&nbsp;</p>
        <p>&nbsp;</p>
      </blockquote></td>
  </tr>
</table>
</body>
</html>

Again, thank you all for youe help,
ISM
0
 
substandCommented:
ok make this your queries:

<cfquery name="SurveyDetails" datasource="#Application.Datasource#">
SELECT unique AnswerID, ChoiceText, ChoiceOrder
FROM TblSurveyAnswers
WHERE Question = #Form.question#
order by choiceorder
</cfquery>
<cfoutput query="surveydetails">
#printYourQuestionherefromtheQuestionQuery#
<cfquery name="numtimes" datasource="#application.datasource#">
select count(*) as theCount from TblSurveyAnswers
where answerID=#answerID#;
</cfquery>
#choiceText#: #numtimes.theCount#<br>
</cfoutput>
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now