Solved

Another Looping Query containg Drop Down List

Posted on 2003-10-29
6
242 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
Connect further...control easier

With the ATEN CE624, you can now enjoy a high-quality visual experience powered by HDBaseT technology and the convenience of a single Cat6 cable to transmit uncompressed video with zero latency and multi-streaming for dual-view applications where remote access is required.

 

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

Building an interactive eFuture classroom

Watch and learn how ATEN provided a total control system solution including seamless switching matrix switch, HDBaseT extenders, PDU, lighting control to build an interactive eFuture classroom.

Question has a verified solution.

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

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…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

623 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