Solved

URGENT!! A-Z List/ Display Query

Posted on 2002-06-21
15
274 Views
Last Modified: 2013-12-24
Hello,  I would to create a list that goes from A-Z and when I user clicks on it, it will query the database show the results that start with the letter they chose.  The only other part is that there will be several categories they can choose from a drop down box...  

So first they will choose their category
Then they will pick a letter thats a hyperlink
A B C D E F G and so on

then the results will be shown.

Thank you!
0
Comment
Question by:jeffmace
  • 5
  • 5
  • 5
15 Comments
 
LVL 5

Expert Comment

by:Yog
ID: 7099460
page1.cfm


<script>
function doit(link) {
 var iIndex = document.myform.category.selectedIndex
 var catId = document.myform.category[iIndex].value
 window.location.href = "page1.cfm?link=" + link + "cat=" + catID
}
</script>

<form name="myform">

<cfquery name="getcategory" datasource="test">
select * from category
</cfquery>

<select name="category">
<cfoutput query = "getcategory">
<option value="#categoryid#"> #categoryname#
</cfoutput>
</select>

<a href="javascript:doit('A')"> A </a>
<a href="javascript:doit('B')"> B </a>
--
--
<a href="javascript:doit('Z')"> Z </a>

<CFQUERY NAME="SEARCHQUERY" ....>

SELECT * FROM TABLENAME
WHERE NAME LIKE '%#url.link#'
AND CATEGORYID = #URL.CATID#
</CFQUERY>
</form>

If its a different table, you need a join blah blah..
0
 

Author Comment

by:jeffmace
ID: 7099496
This looks good, but I am getting an error... Do we have to specify a <CFPARAM> or something so when the page loads you don't get an error like this:

An error occurred while evaluating the expression:

#url.link#

Error near line 32, column 27.

How can I specigy the letter 'A' or something, becuase I think its looking for a letter to load by defaut... What do you think??
0
 
LVL 5

Expert Comment

by:Yog
ID: 7099532
hi jeff yeah, you are right

<cfparam name="link" default="A">

and in the query just change like

<CFQUERY NAME="SEARCHQUERY" ....>

SELECT * FROM TABLENAME
WHERE NAME LIKE '%#url.link#'

<cfif isdefined("url.cat")>
AND CATEGORYID = #URL.CAT#
</cfif>

</CFQUERY>
0
 
LVL 5

Expert Comment

by:Yog
ID: 7099539
sorry this can be

WHERE NAME LIKE '#url.link#%'

'%' at the end, meaning begins with A..., B...etc

0
 

Author Comment

by:jeffmace
ID: 7099738
This is the code I have.. I am still getting the same error:


<cfparam name="link" default="A">

<script>
function doit(link) {
var iIndex = document.form.category.selectedIndex
var catId = document.form.category[iIndex].value
window.location.href = "letter.cfm?link=" + link + "cat=" + catID
}
</script>

<cfquery name="getLetters" datasource="#Data#">
Select * from Letters
ORDER by Letter ASC
</cfquery>

<form name="form">
<cfquery name="getcategory" datasource="#Data#">
select * from pt_linkcat
</cfquery>

<select name="category">
<cfoutput query = "getcategory">
<option value="#pt_linkcatID#"> #pt_linkCatName#
</cfoutput>
</select>

<cfoutput query="getLetters">
<a href="javascript:doit('#letter#')">#letter#</a>&nbsp;
</cfoutput>

<CFQUERY NAME="SEARCHQUERY" datasource="#Data#">
SELECT pt_linkcat.pt_linkcatName, pt_link.*
FROM pt_link INNER JOIN pt_linkcat ON pt_link.pt_linkcatID = pt_linkcat.pt_linkcatID
WHERE pt_linkName LIKE '#url.link#%'
<cfif isdefined("url.cat")>
AND pt_linkcatID = #URL.CATID#
</cfif>
</CFQUERY>
</form>

<cfoutput query="SEARCHQUERY">
#pt_linkName#
</cfoutput>


0
 

Author Comment

by:jeffmace
ID: 7099741
Also here is the test page so that you can see the error using this code:

http://216.234.242.114/letter.cfm
0
 
LVL 6

Expert Comment

by:dash420
ID: 7100108
You mean to write in the same page user will choose the category then click the hyperlink to get result.

Here is the code for that.

I did this page name as test.cfm

<script language="JavaScript">
  function fntest(val){
     document.frmtest.hdnlink.value = val
       document.frmtest.method = "post"
       document.frmtest.action = "test5.cfm"
       document.frmtest.submit()
  }
</script>
<body>
<form name="frmtest">


<select name="lstCategory">
    <option value="">All
    <option value="1">Category1
     <option value="2">Category2
     <option value="3">Category3
 </select>
 <br>
 
 <cfloop index="i" from="65" to="90">
    <cfif url.link is not #chr(i)#>
       <a href="test5.cfm" onclick="fntest('#chr(i)#');return false;">#chr(i)#</a>
     <cfelse>
        #chr(i)#  
     </cfif>  
 </cfloop>
 
 
<cfquery name="qrytest" datasource="dsn>
   SELECT * FROM TABLENAME
   WHERE 1 = 1
   <cfif isDefined("form.hdnlink") and form.hdnlink is   not "">
      AND UPPER(NAME) LIKE '#form.hdnlink#%'
   </cfif>
   <cfif isdefined("form.lstCategory") and form.lstCategory is not "">
     AND CATEGORY_ID = #form.lstCategory#
   </cfif>
</cfquery>
<br>
<cfoutput>
  <cfloop query="qrytest">
     #first_name#<br>
  </cfloop>  
</cfoutput>
</form>
</body>

I just the code you can format it according to your requirement.




0
Scale it in WD Gold

With up to ten times the workload capacity of desktop drives, WD Gold hard drives employ advanced technology to deliver among the best in reliability, capacity, power efficiency and performance.

 
LVL 6

Expert Comment

by:dash420
ID: 7100116
there is some typo error, please modified it as

<cfloop index="i" from="65" to="90">
    <cfif isDefined("form.hdnlink") and form.hdnlink is not #chr(i)#>
       <a href="test.cfm" onclick="fntest('#chr(i)#');return false;">#chr(i)#</a>
     <cfelse>
        #chr(i)#  
     </cfif>  
 </cfloop>

0
 
LVL 6

Expert Comment

by:dash420
ID: 7100204
please make following line just above this loop
like

<cfparam name="form.hdnlink" default="A">

<cfloop index="i" from="65" to="90">
............
</cfloop>


actually there is no edit option edit your answer/comment.
once u submit it becoemes readonly. i just saw that there is no cfparam. so no link will comes. as it will always go to else part and form.hdnlink always will not be defined.

already three time i posted my answer with some modificatio hope this will be the last.
0
 

Author Comment

by:jeffmace
ID: 7100499
Here is the code I am using for dash420s code but getting errors:

<script language="JavaScript">
 function fntest(val){
    document.frmtest.hdnlink.value = val
      document.frmtest.method = "post"
      document.frmtest.action = "test5.cfm"
      document.frmtest.submit()
 }
</script>
<body>
<form name="frmtest">

<cfquery name="getcategory" datasource="#Data#">
select * from pt_linkcat
</cfquery>

<select name="lstCategory">
<cfoutput query = "getcategory">
<option value="#pt_linkcatID#"> #pt_linkCatName#
</cfoutput>
</select>
<br><br>


<cfparam name="form.hdnlink" default="A">

<cfloop index="i" from="65" to="90">
   <cfif isDefined("form.hdnlink") and form.hdnlink is not #chr(i)#>
      <a href="test.cfm" onclick="frmtest('#chr(i)#');return false;">#chr(i)#</a>
    <cfelse>
       #chr(i)#  
    </cfif>  
</cfloop>
 

<cfquery name="qrytest" datasource="#data#">
  SELECT pt_linkcat.pt_linkcatName, pt_link.*
  FROM pt_link INNER JOIN pt_linkcat ON pt_link.pt_linkcatID = pt_linkcat.pt_linkcatID
  WHERE 1 = 1
  <cfif isDefined("form.hdnlink") and form.hdnlink is not "">
     AND UPPER(NAME) LIKE '#form.hdnlink#%'
  </cfif>
  <cfif isdefined("form.lstCategory") and form.lstCategory is not "">
    AND pt_linkcatID = #form.lstCategory#
  </cfif>
</cfquery>
<br>
<cfoutput>
 <cfloop query="qrytest">
    #pt_linkName#<br>
 </cfloop>  
</cfoutput>
</form>
</body>

Also here is the link to the page so you can see whats going on: http://216.234.242.114/test5.cfm
0
 
LVL 6

Expert Comment

by:dash420
ID: 7102635
please embeded this code with cfoutpt
like
<cfoutput>
<cfloop index="i" from="65" to="90">
  <cfif isDefined("form.hdnlink") and form.hdnlink is not #chr(i)#>
     <a href="test.cfm" onclick="frmtest('#chr(i)#');return false;">#chr(i)#</a>
   <cfelse>
      #chr(i)#  
   </cfif>  
</cfloop>
</cfoutput>

0
 
LVL 6

Expert Comment

by:dash420
ID: 7102647
first error is
Microsoft][ODBC SQL Server Driver][SQL Server]Invalid column name 'NAME'.

I think the table don't have the column name 'NAME'. Check it.

second one is because the value gone as #chr(i)# instead of 'A', 'B','C', so on.
so put cfoutput between cfloop for displaying A,B..
0
 
LVL 5

Accepted Solution

by:
Yog earned 500 total points
ID: 7104281
jeff, instead of #URL.link#, use #link# in your query

<cfparam name="link" default="A">

<script>
function doit(link) {
var iIndex = document.form.category.selectedIndex
var catId = document.form.category[iIndex].value
window.location.href = "letter.cfm?link=" + link + "cat=" + catID
}
</script>

<cfquery name="getLetters" datasource="#Data#">
Select * from Letters
ORDER by Letter ASC
</cfquery>

<form name="form">
<cfquery name="getcategory" datasource="#Data#">
select * from pt_linkcat
</cfquery>

<select name="category">
<cfoutput query = "getcategory">
<option value="#pt_linkcatID#"> #pt_linkCatName#
</cfoutput>
</select>

<cfoutput query="getLetters">
<a href="javascript:doit('#letter#')">#letter#</a>&nbsp;
</cfoutput>

<CFQUERY NAME="SEARCHQUERY" datasource="#Data#">
SELECT pt_linkcat.pt_linkcatName, pt_link.*
FROM pt_link INNER JOIN pt_linkcat ON pt_link.pt_linkcatID = pt_linkcat.pt_linkcatID
WHERE pt_linkName LIKE '#link#%'
<cfif isdefined("url.cat")>
AND pt_linkcatID = #URL.CATID#
</cfif>
</CFQUERY>
</form>

<cfoutput query="SEARCHQUERY">
#pt_linkName#
</cfoutput>
0
 

Author Comment

by:jeffmace
ID: 7162583
This worked with a little modificat from my code... but you had the right thing going.. thanks and sorry for the delay.
0
 
LVL 5

Expert Comment

by:Yog
ID: 7164974
thanks jeff, you are welcome :)
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

Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

895 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

13 Experts available now in Live!

Get 1:1 Help Now