Solved

Another Looping Query containg Drop Down List

Posted on 2003-10-29
6
220 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

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…
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 tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

809 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