Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.
-
EnergyFed #1
Need help with advanced search please!!
I am trying to create a search that searches two fields and highlights the
search term. How can I do this? Here is my code as of now:
<cfquery name="addfaq" datasource="stuff">
SELECT *
FROM FAQ
WHERE (0=0
<CFLOOP list="%#FORM.search#%" index="thisword" delimiters=" ">
AND (Answer LIKE '%#thisword#%' OR Question LIKE '%#thisword#%')
</CFLOOP>)
ORDER BY ID ASC
And I have this in the body:
<cfoutput query="addfaq" startRow="#StartRow_addfaq#"
maxRows="#MaxRows_addfaq#">
<tr>
<td><div align="center">#addfaq.Date#</div></td>
<td><div align="center"><a
href="faq_detail.cfm?recordID=#addfaq.ID#">#addfaq .ItemNumber#</a></div></td>
<td>#Replace(addfaq.Question, "%#FORM.search#%", "<span
bgcolor='yellow'>%#FORM.search#%</span>", "ALL")#</td>
<td><div align="center">#addfaq.Answer#</div></td>
<td><div align="center">#addfaq.Verified#</div></td>
</tr>
</cfoutput>
Any help on this would be great!!!
EnergyFed Guest
-
advanced search with php
Does anybody know of a good tutorial on how to do a search for any/all words with php? Thanks -
Advanced search (Verity)
Somebody, please help me! Tell me how I can search and select from results entries of sought word only within title, body, URL, alternate text and... -
advanced search
hi, I building a advanced search funcationality with 3 listbox and 5 checkbox so want I want that you can search with all possible ways' cross... -
ANN: InterAKT Site Search - search in multiple tables
Hello, We have just released a new product, MX Site Search, meant to help web developers and designers create a search form in their dynamic... -
#25786 [NEW]: PHP website uses cookies to remember last search phrase in search box
From: tipsen at imada dot sdu dot dk Operating system: - PHP version: Irrelevant PHP Bug Type: Unknown/Other Function Bug... -
MikerRoo #2
Re: Need help with advanced search please!!
Your code looks like it should work except for a few things:
1) bgcolor is not a valid attribute for <span> so this will not work on many
(any?) browsers.
2) FORM.search is a list of words, so they must be highlighted separately.
3) "%#FORM.search#%" should probably be "#FORM.search#"
Also,
Do you want to highlight the words in the answer too?
Do you want the highlight to be case sensitive? Is the search?
Replace your body with the attached code. I have not tested it so beware of
typos.
Cheers,
-- MikeR
<!--- Local function for easier coding. --->
<CFFUNCTION name="sHighLightKeyWords" returnType="string" output="no">
<CFARGUMENT name="sRawText" type="string" required="Yes">
<CFARGUMENT name="sListOfKeyWords" type="string" required="Yes">
<CFARGUMENT name="sListDelimiter" type="string" default=" ">
<CFSET var sProcessedText = sRawText>
<CFLOOP list="#sProcessedText#" index="sKeyWord"
delimiters=#sListDelimiter#>
<CFSET sProcessedText = ReplaceNoCase
(
sProcessedText,
sKeyWord,
'<span
class="HighLighted">#sKeyWord#</span>',
"ALL"
)</CFLOOP>>
<CFRETURN sProcessedText>
</CFFUNCTION>
<!--- Use CSS for cleaner, easier html. --->
<CFOUTPUT>
<style type="text/css">
.HighLighted
{
background-color: yellow;
}
td.CenterCell
{
text-align: center;
}
</style>
</CFOUTPUT>
<!--- Note that it may be more efficient to save this entire loop's output
using
cfsavecontent, and then do the string replace only once.
--->
<CFOUTPUT query="addfaq" startRow="#StartRow_addfaq#"
maxRows="#MaxRows_addfaq#">
<tr>
<td class="CenterCell">#addfaq.Date#</td>
<td class="CenterCell"><a
href="faq_detail.cfm?recordID=#addfaq.ID#">#addfaq .ItemNumber#</a></td>
<td class="CenterCell">#sHighLightKeyWords (addfaq.Question,
FORM.search)#</td>
<td class="CenterCell">#sHighLightKeyWords (addfaq.Answer,
FORM.search)#</td>
<td class="CenterCell">#addfaq.Verified#</td>
</tr>
</CFOUTPUT>
MikerRoo Guest
-



Reply With Quote

