Solved

Another Looping Query containg Drop Down List

Posted on 2003-10-29
6
235 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 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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 

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

Manage your data center from practically anywhere

The KN8164V features HD resolution of 1920 x 1200, FIPS 140-2 with level 1 security standards and virtual media transmissions at twice the speed. Built for reliability, the KN series provides local console and remote over IP access, ensuring 24/7 availability to all servers.

Question has a verified solution.

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

Suggested Solutions

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…
Lease-to-own eliminates the expenditure of hardware replacement and allows you to pay off the server over time. Usually, this is much cheaper than leasing servers. Think of lease-to-own as credit without interest.

739 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