User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ColdFusion section within the Web Development category of DaniWeb, a massive community of 332,570 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,150 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ColdFusion advertiser:
Views: 437 | Replies: 1
Reply
Join Date: Feb 2006
Posts: 2
Reputation: krazykrisi is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
krazykrisi krazykrisi is offline Offline
Newbie Poster

survey code not working

  #1  
Apr 7th, 2008
Ok so I'm making a survey for a website and I have a series of questions where the user can rate it from a list of choices and I have these questions in a table in access and the rating options in a table. I want to have the questions display with the options in a dropdown box next to each question, I can't seem to get this to work. Here is my code:

  1. <!--- Get ratings --->
  2. <cfquery datasource="PFB" name="RatingsQ">
  3. SELECT *
  4. FROM Ratings, Questions
  5. ORDER BY RatingID, QuestionID
  6. </cfquery>
  7. <!--- Get genders --->
  8. <cfquery datasource="PFB" name="Gender">
  9. SELECT *
  10. FROM Gender
  11. ORDER BY ID
  12. </cfquery>
  13. <!--- Get states --->
  14. <cfquery datasource="PFB" name="State">
  15. SELECT *
  16. FROM State
  17. ORDER BY StateID
  18. </cfquery>
  19.  
  20. <!--- Get questions2 --->
  21. <cfquery datasource="PFB" name="Questions2">
  22. SELECT *
  23. FROM Questions2
  24. ORDER BY Question_ID
  25. </cfquery>
  26. <!----get ages----->
  27. <cfquery datasource="PFB" name="Age">
  28. SELECT ID, Age
  29. FROM Age
  30. ORDER BY ID
  31. </cfquery>
  32. <html>
  33. <body>
  34. <cfform action="insertnewreview.cfm">
  35. <table>
  36. <tr>
  37. <td>Age:</td>
  38. <td> <select name="AgeID">
  39. <cfoutput query="Age">
  40. <option value="#ID#">#Age#</option></cfoutput>
  41. </select>
  42. </td>
  43. </tr>
  44. <tr>
  45. <td>
  46. Gender:
  47. </td>
  48. <td>
  49. <select name="Gender">
  50. <cfoutput query="Gender">
  51. <option value="#Gender#">#Gender#</option></cfoutput>
  52. </select>
  53. </td>
  54. </tr>
  55. <tr>
  56. <td>
  57. State:
  58. </td>
  59. <td>
  60. <select name="State">
  61. <cfoutput query="State">
  62. <option value="#State#">#State#</option></cfoutput>
  63. </select>
  64. </td>
  65. </tr>
  66. <tr>
  67. <td><cfoutput query="RatingsQ"><br><br>#Question#</td><td><select name="RatingID"><option value="#RatingID#">#Rating#</option>
  68. </select></cfoutput></td></tr>
  69.  
  70.  
  71. <tr>
  72. <td><cfoutput query="Questions2">#Q#:</cfoutput></td>
  73. <td>Answer: <textarea></textarea></td>
  74. </tr>
  75. <tr>
  76. <td colspan="2" align="center">
  77. <input type="submit" value="Insert"></td>
  78. </tr>
  79. </table>
  80. </cfform>
  81. </body>
  82. </html>
Last edited by peter_budo : Apr 7th, 2008 at 7:02 pm. Reason: Keep It Organized - please use [code] tags
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Feb 2008
Posts: 32
Reputation: cmhampton is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 3
cmhampton cmhampton is offline Offline
Light Poster

Re: survey code not working

  #2  
Apr 10th, 2008
The group attribute of cfquery is one of the most unknown and under-appreciated pieces of the entire language. It's so incredibly simple to use it's a wonder more people aren't told about it.

I modified your output to use grouping and it should make your life a little easier (programming life at least, I'm not a messiah )...

Take a look at lines 67-83

  1. <!--- Get ratings --->
  2. <cfquery datasource="PFB" name="RatingsQ">
  3. SELECT *
  4. FROM Ratings, Questions
  5. ORDER BY RatingID, QuestionID
  6. </cfquery>
  7. <!--- Get genders --->
  8. <cfquery datasource="PFB" name="Gender">
  9. SELECT *
  10. FROM Gender
  11. ORDER BY ID
  12. </cfquery>
  13. <!--- Get states --->
  14. <cfquery datasource="PFB" name="State">
  15. SELECT *
  16. FROM State
  17. ORDER BY StateID
  18. </cfquery>
  19. <!--- Get questions2 --->
  20. <cfquery datasource="PFB" name="Questions2">
  21. SELECT *
  22. FROM Questions2
  23. ORDER BY Question_ID
  24. </cfquery>
  25. <!----get ages----->
  26. <cfquery datasource="PFB" name="Age">
  27. SELECT ID, Age
  28. FROM Age
  29. ORDER BY ID
  30. </cfquery>
  31. <html>
  32. <body>
  33. <cfform action="insertnewreview.cfm">
  34. <table>
  35. <tr>
  36. <td>Age:</td>
  37. <td>
  38. <select name="AgeID">
  39. <cfoutput query="Age">
  40. <option value="#ID#">#Age#</option>
  41. </cfoutput>
  42. </select>
  43. </td>
  44. </tr>
  45. <tr>
  46. <td> Gender: </td>
  47. <td>
  48. <select name="Gender">
  49. <cfoutput query="Gender">
  50. <option value="#Gender#">#Gender#</option>
  51. </cfoutput>
  52. </select>
  53. </td>
  54. </tr>
  55. <tr>
  56. <td> State: </td>
  57. <td>
  58. <select name="State">
  59. <cfoutput query="State">
  60. <option value="#State#">#State#</option>
  61. </cfoutput>
  62. </select>
  63. </td>
  64. </tr>
  65.  
  66. <!--- Updated grouping here --->
  67. <cfoutput query="RatingsQ" group="QuestionID">
  68. <tr>
  69. <td>
  70. <br>
  71. <br>
  72. #Question#
  73. </td>
  74. <td>
  75. <cfoutput>
  76. <select name="RatingID">
  77. <option value="#RatingID#">#Rating#</option>
  78. </select>
  79. </cfoutput>
  80.  
  81. </td>
  82. </tr>
  83. </cfoutput>
  84.  
  85. <!--- Changed this cfoutput --->
  86. <cfoutput query="Questions2">
  87. <tr>
  88. <td>#Q#:</td>
  89. <td>
  90. Answer:
  91. <textarea></textarea>
  92. </td>
  93. </tr>
  94. </cfoutput>
  95. <tr>
  96. <td colspan="2" align="center"><input type="submit" value="Insert"></td>
  97. </tr>
  98. </table>
  99. </cfform>
  100. </body>
  101. </html>

I also changed lines 85-94 a little to make the output of the Question2 section a little cleaner.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb ColdFusion Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the ColdFusion Forum

All times are GMT -4. The time now is 12:10 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC