Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search Feature

Status
Not open for further replies.

tsp1lrk

IS-IT--Management
Joined
May 30, 2001
Messages
103
Location
US
HI! I have a small search feature, I guess it's more like just querying some tables. Right now people just pick from a drop down menu and choose something, like Windows 2000, it will show all the Windows 2000 articles. What I want to do, is add a keyword search so instead of choosing Windows NT from a drop down menu, they can also type in a text box "NT" and it will show everything with an "NT" in the results. Here is the first page of code:

<cfif #ParameterExists(Cookie.USERID)# IS &quot;NO&quot;>
<cfinclude template=&quot;login.cfm&quot;>
<cfabort>
<cfelse>
</cfif>

<CFSET TITLE = &quot;Tech Tips Search&quot;>
<!--- <CFINCLUDE TEMPLATE=&quot;_header.cfm&quot;> --->

<CFQUERY datasource=&quot;2029_ACC_85005_Procedures&quot; NAME=&quot;GetTips&quot;>
SELECT *
FROM tblCategory
</CFQUERY>
<html>
<head>
<title>Campus Only Web Forms</title>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>
</head>

<BODY BGCOLOR=#000033 TEXT=&quot;silver&quot; LINK=&quot;blue&quot; VLINK=&quot;purple&quot;>
<table border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; align=&quot;center&quot; bgcolor=&quot;#000066&quot; width=620 height=&quot;372&quot;>
<tr>
<td width=&quot;15&quot; height=&quot;77&quot;>&nbsp;</td>
<td height=&quot;77&quot;>&nbsp; </td>
<td align=&quot;right&quot; height=&quot;77&quot;> <font face=&quot;Myriad Web, Verdana, Helvetica&quot; size=&quot;+2&quot;><br>
<b><font size=&quot;+3&quot;>Campus Only</font></b><br>
</font> <font face=&quot;Times&quot;><br>
<i>Restricted to Campus Personnel<br>
</i></font> </td>
<td width=&quot;50&quot; height=&quot;77&quot;>&nbsp;</td>
</tr>
<tr>
<td height=&quot;35&quot; colspan=&quot;4&quot; bgcolor=&quot;#ffffff&quot;>
<table width=&quot;98%&quot; border=&quot;0&quot;>
<tr>
<td width=&quot;22%&quot; height=&quot;45&quot;><IMG alt=&quot;&quot; border=0 height=75 src=&quot;../../images/CS_LOGO.jpg&quot; width=93></td>
<td width=&quot;78%&quot; height=&quot;45&quot;>
<blockquote>
<FORM action=results.cfm method=post>


<P><font color=&quot;Black&quot; face=&quot;Arial, Helvetica, sans-serif&quot; size=&quot;2&quot;><b>Choose
by Category:</b></font><font face=&quot;Arial, Helvetica, sans-serif&quot; size=&quot;2&quot;><br>
<BR>
</font>
<P><font color=&quot;Black&quot; face=&quot;Arial, Helvetica, sans-serif&quot; size=&quot;2&quot;>Tech
Tip Categories</font><font face=&quot;Arial, Helvetica, sans-serif&quot; size=&quot;2&quot;><BR>
<SELECT name=Keyword>
<OPTION selected><font color=&quot;Black&quot;>Choose </font>
<CFOUTPUT QUERY=&quot;GetTips&quot;>
<OPTION
value=#CategoryID#>#CategoryName#</OPTION>
</cfoutput>
</SELECT>
</font></P>
<p><font color=&quot;Black&quot; face=&quot;Arial, Helvetica, sans-serif&quot; size=&quot;2&quot;>Number
of records to display per page:</font> <font face=&quot;Arial, Helvetica, sans-serif&quot; size=&quot;2&quot;>
<SELECT name=records_to_display>
<OPTION
selected>5
<OPTION>10
<OPTION>20
<OPTION>30
<OPTION>40</OPTION>
</SELECT>
</font></p>
<p><font face=&quot;Arial, Helvetica, sans-serif&quot; size=&quot;2&quot;><BR>
<INPUT type=submit value=Search>
<BR>
</font> </p>
<P><font face=&quot;Arial, Helvetica, sans-serif&quot; size=&quot;2&quot;><A href=&quot;../../content/TechTips/TECHTIPS.htm&quot;>Show
all Tech Tips</A> </font>
</FORM>
</blockquote>
</td>
</tr>
<tr>
<td width=&quot;22%&quot;>&nbsp; </td>
<td width=&quot;78%&quot;>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td height=&quot;84&quot; colspan=&quot;4&quot; bgcolor=&quot;#ffffff&quot;>
<DIV align=left><IMG alt=&quot;&quot; border=0 height=69 src=&quot;../../images/4_web.jpg&quot; width=338><br></DIV>
</td>
</tr>
<tr>
<td height=&quot;21&quot; colspan=&quot;4&quot;>
<p>&nbsp;</p></td></tr>

</table><cfinclude template=&quot;_footer.cfm&quot;>
<div align=&quot;center&quot;><br>
</div>
</BODY>
</html>



Results Page:

<HTML>
<HEAD>

<TITLE>Results Page</TITLE>

<!-- This Query retrieves the tech tips from the database -->
<CFQUERY DATASOURCE=&quot;2029_acc_85005_procedures&quot; NAME=&quot;RetreiveInfo&quot;>
SELECT A.*, B.CategoryName
FROM tbltips A, tblcategory B
WHERE A.CategoryID=B.CategoryID AND B.CategoryID='#Keyword#'
</CFQUERY>

<!-- If the user access this page for the first time, we set the_start value at 1 -->
<CFPARAM NAME=&quot;the_start&quot; DEFAULT=&quot;1&quot;>

<!-- If the the_start is already defined, then we had 5 to it to calculate the value of next_start -->
<CFIF ISDEFINED(&quot;the_start&quot;)>
<CFSET NEXT_START = #THE_START# + #RECORDS_TO_DISPLAY#>
</CFIF>
</HEAD>
<BODY>
<CFOUTPUT>
There are <b>&quot;#RetreiveInfo.RecordCount#&quot; </b>records in the Database.<BR><BR>
</CFOUTPUT>

<TABLE CELLPADDING=&quot;2&quot; CELLSPACING=&quot;2&quot;>
<TH>Row</TH><TH>Category Name</TH><TH>Question</TH><TH>Provided By</TH>
<CFOUTPUT QUERY=&quot;RetreiveInfo&quot; STARTROW=&quot;#the_start#&quot; MAXROWS=&quot;#records_to_display#&quot;>
<TR>
<TD ALIGN=&quot;center&quot;>#CurrentRow#</TD>
<TD>#CategoryName#</TD>
<td><A HREF=&quot;#Article#&quot;>#Question#</A></td>
<TD>#ProvidedBy#</TD>
</TR>
</CFOUTPUT>
</TABLE>

<CFOUTPUT>
<!-- the previous button will not be displayed if there's no more record left to display before this page -->
<CFIF #THE_START# IS NOT 1>
<A HREF=&quot;results.cfm?the_start=#Evaluate(the_start - records_to_display)#&records_to_display=#records_to_display#&Keyword=#Keyword#&quot;>Previous #records_to_display#</A>
</CFIF>

<!-- the next button will not be displayed if there's no more record left to display after this page -->
<CFIF #NEXT_START# LTE RETREIVEInfo.RECORDCOUNT>
<!-- If the next page is the last one, we check how many records are left and display the right count inside the link -->
<CFIF #EVALUATE(NEXT_START + #RECORDS_TO_DISPLAY# - 1)# GT RETREIVEInfo.RECORDCOUNT>
<CFSET NEXT_RECORDS_COUNT = #RETREIVEInfo.RECORDCOUNT# MOD #RECORDS_TO_DISPLAY#>
<A HREF=&quot;results.cfm?the_start=#next_start#&records_to_display=#records_to_display#&Keyword=#Keyword#&quot;>Next #next_records_count#</A>
<CFELSE>
<A HREF=&quot;results.cfm?the_start=#next_start#&records_to_display=#records_to_display#&Keyword=#Keyword#&quot;>Next #records_to_display#</A>
</CFIF>
</CFIF>
</CFOUTPUT>

</BODY>
</HTML>

I'm not sure how to incorporate a simple keyword search... Any assitance is appreciated. Thanks,

Lisa
 
If I may make a suggestion Lisa..never post your DSN within the code you display in any forum - just substitute it with something like &quot;MyDSN&quot;

another suggestion is rather than posting the whole code (whith all the html) just cut and past what is relevant to your quandry - it becomes easier to scan.

Hope I was not too rude...

Here is the code on an action page that I use when I want people to do a keyword search.. it is primitive but works..

<CFQUERY NAME=&quot;search_result&quot; DATASOURCE=&quot;DSN&quot;>
SELECT *
FROM table
WHERE table.field like '%#keyword#%'
</CFIF>
</CFQUERY>
___________________
HTH..!
 
Why re-invent the wheel?

Go to they will index your site (if its available online) and provide you with search box code that you paste into your site to allow your users to search your site. Its extremly flexible and support is good and best of all its free for sites under 500 pages. Your search results page can be customised to retain the look and feel of your site. There are lots of features like highlighting the terms and ordering. Its what webmonkey and macromedia use on their site. check it out.

Oh and before you ask no i am not affiliated with the company in anyway I used it on:


HTH

Kola
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top