Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Another Looping Query containg Drop Down List

Posted on 2003-10-29
6
Medium Priority
?
247 Views
Last Modified: 2013-12-24
Hi

I have a database which holds frequently asked questions.  There are basically four fields:

ID, CATEGORY, QUESTION, ANSWER

To make it easier for people to search for these questions I would like to set out the FAQs page as follows:

CATEGORY1
Drop down list containing all of the questions for CATEGORY1.

CATEGORY2
Drop down list containing all of the questions for CATEGORY2

CATEGORY3, etc, etc...

I would like each drop downlist links to a separate page which holds all the answers for that category.

Each question on the answer page will have it's own anchor named with the ID from the database. So by clicking on the question from the dropdown list the user goes straight to the answer.

I hope this is clear in principle.  Can anyone help me put this into action?

Thanks in advance.
0
Comment
Question by:nelliott
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 9

Accepted Solution

by:
CFDevHead earned 2000 total points
ID: 9642502
try this <cfquery datasource="#dsn#" name="getFAQS">
Select ID, CATEGORY, QUESTION, ANSWER from FAQS Order by CATEGORY
</cfquery>
<script>

function gotosite(url){
      window.location.href=url;

}
</script>
<cfoutput>
<cfset tempCategory=''>

<cfloop query="getFAQS">
      <cfif tempCategory is not Category>
            #iif(getFAQS.currentrow is not 1,"'</select>'","''")#
            <select name="#Category#" onChange="gotosite(this.options[this.selectedIndex].value)">            
            <cfset tempCategory=Category>
      </cfif>
            <option value="actionPage.cfm?###ID#">QUESTION</option>
            #iif(getFAQS.currentrow is getFAQS.recordcount,"'</select>'","''")#      
</cfloop>

</cfoutput>
0
 
LVL 6

Expert Comment

by:PE_CF_DEV
ID: 9642730
<cfquery datasource="#dsn#" name="getFAQS">
Select ID, CATEGORY, QUESTION from FAQS Order by CATEGORY
</cfquery>
<form action="template.cfm" method="post">
<cfoutput query="getFAQS" group="CATEGORY" groupcasesensitive="no">
      <select name="question">
      <cfoutput>
      <option value="#CATEGORY#,#ID#">#QUESTION#</option>
      </cfoutput>
      </select>
</cfoutput>
<!--- Other form stuff if needed --->
</form>

Then on th next page listfirst form.question will give you the category to select from and listlast will give you the ID which you could put at the top of the page instead of using an anchor, or you could set a javascript up to onload go to that anchor on the page.
0
 
LVL 4

Expert Comment

by:procept
ID: 9642779
Hi,

a few changes to CFDevHead's script:

- use grouping in output to make things easier. ;-))
- no need to use a separate JS function

<cfquery name="qryFAQs" datasource="myDatasource">
   SELECT *
   FROM tblFAQs
   ORDER BY Category
</cfquery

<form name="myForm">
<cfset cat="0">
<cfoutput query="qryFAQs" group="category">
   <cfset cat = cat +1>
   #qryFAQs.category#<br>
   <select name="category#cat#" onChange="window.location.href='answerpage.cfm##' + this.options[this.selectedIndex].value">
      <option value="0">--- please select ---</option>
      <cfoutput>
         <option  value="#qryFAQs.ID#">#qryFAQs.question#</option>
      </cfoutput>
   </select>
   <p>
</cfoutput>
</form>

BUT.... I don't think it is a good idea to post all answers on one page. That page could become long and take long to load.

Instead, pass the ID of the desired answer to a page and select only that question and answer there:

First, change the select:
<select name="category#cat#" onChange="window.location.href='answerpage.cfm?ID=' + this.options[this.selectedIndex].value">

Then, select the question and the answer on the answer page:

<cfquery name="qryAnswer" datasource="myDatasource">
   SELECT *
   FROM tblFAQs
   WHERE ID = #URL.ID#
</cfquery>

<cfoutput query="qryAnswer">
Question in category #qryAnswer.category#:<br>
#qryAnswer.question#<br>
Answer: #qryAnswer.answer#

HTH,

Chris






0
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 

Author Comment

by:nelliott
ID: 9642799
Fair Play CFDevHead

Worked a treat!
0
 
LVL 9

Expert Comment

by:CFDevHead
ID: 9642822
What
0
 
LVL 4

Expert Comment

by:procept
ID: 9643065
that's OK, my addition was just minor changes. :-))

Chris
0

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a guide to setting up a new WHM/cPanel Server to be used for web hosting accounts. It is intended for web hosting company administrators and dedicated server owners. For under $99 per month (considering normal rate of Big Data Cetnters like …
One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question