Link to home
Start Free TrialLog in
Avatar of jeffmace
jeffmace

asked on

URGENT!! A-Z List/ Display Query

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!
Avatar of Yog
Yog

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..
Avatar of jeffmace

ASKER

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??
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>
sorry this can be

WHERE NAME LIKE '#url.link#%'

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

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>


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

http://216.234.242.114/letter.cfm
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.




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>

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.
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
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>

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..
ASKER CERTIFIED SOLUTION
Avatar of Yog
Yog

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This worked with a little modificat from my code... but you had the right thing going.. thanks and sorry for the delay.
thanks jeff, you are welcome :)