| | |
Coldfusion search multiple words.
Please support our ColdFusion advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Apr 2009
Posts: 7
Reputation:
Solved Threads: 0
Hi,
I would like to search one field in database with multiple words. Also i will allow searches for example : a or cs....(one,two characters).
My code:
this code works fine but only with one word or if there is exact match with multiple words.
Example:
database rows:
1.adobe photohop
2.adobe photoshop cs4
search string adobe(my code) will display both results,but
search string adobe cs4 will not display results. I want if user type one,two, three words to match any of these words and to display all results like google.
What am I doing wrong? I also tried to replace characters and add + but no results.
Any idea or example i would appreciate.
I would like to search one field in database with multiple words. Also i will allow searches for example : a or cs....(one,two characters).
My code:
ColdFusion Syntax (Toggle Plain Text)
<cfparam name="URL.NAME" default="1" type="Any"> <cfquery name="search" datasource="datasource"> SELECT * FROM search WHERE NAME LIKE ="%#URL.NAME#%" ORDER BY DATE DESC </cfquery>
this code works fine but only with one word or if there is exact match with multiple words.
Example:
database rows:
1.adobe photohop
2.adobe photoshop cs4
search string adobe(my code) will display both results,but
search string adobe cs4 will not display results. I want if user type one,two, three words to match any of these words and to display all results like google.
What am I doing wrong? I also tried to replace characters and add + but no results.
Any idea or example i would appreciate.
•
•
Join Date: Mar 2009
Posts: 8
Reputation:
Solved Threads: 0
0
#4 30 Days Ago
you have to break your input into 2 elements separated by a delimiter(I did it with a space) and put them into an array
now you can easily pass both or either one into your query.
Hope this helps.
coldfusion Syntax (Toggle Plain Text)
<cfparam name="strSearch" default=""> <cfparam name="myArrayList" default=""> <cfset myArrayList=ArrayNew(1)> <cfif isdefined("form.searchMeals") AND form.searchMeals neq ""> <cfset strSearch = #trim(form.searchMeals)#> <cfset strSearch = #lcase(strSearch)#> <cfif strSearch contains ""> <cfset strSearch = Replace(strSearch," ",",")> <cfset myArrayList = ListToArray(strSearch)> <cfif myArrayList[1] neq ""> <cfset element1 = #myArrayList[1]#> </cfif> <cfif strSearch contains ","> <cfset element2 = #myArrayList[2]#> </cfif> </cfif> </cfif>
now you can easily pass both or either one into your query.
Hope this helps.
Last edited by peter_budo; 30 Days Ago at 7:17 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)
![]() |
Similar Threads
- Search from multiple tables ?? (PHP)
- Search multiple words using Find method (VB.NET)
- MySql Search using multiple input. (MySQL)
- swahili english sentence translator (Visual Basic 4 / 5 / 6)
- Count given word (Python)
- Multiple search (PHP)
- Another mysql_num_rows(): error (PHP)
Other Threads in the ColdFusion Forum
- Previous Thread: SubCookies
- Next Thread: Run a CF program as a background process?
| Thread Tools | Search this Thread |





