Solved

Another Looping Query containg Drop Down List

Posted on 2003-10-29
6
198 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
6 Comments
 
LVL 9

Accepted Solution

by:
CFDevHead earned 500 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now