Howdy,
I am working on a system where I need a basic HTML form to pass data to a cfm page. The cfm page will then query a database and return any matching data. I am using MySQL.
I have my HTML page with a form element that allows a user to enter search criteria. When they click submit it sends the data in the text field to a coldfusion page that runs that data through a query to the database. If a match is found it should display the resulting data. The form works, it sends the complete request to the coldfusion page with no problem. The only problem is that when you enter more than one word, even if both of those words are in the database, it doesn't return any records. I'm wondering if anyone has any ideas on how to fix this, I was thinking of somehow breaking the input string into parts and running each individual part by itself, I'm just not sure how to do that.
Here is the HTML form code. - <form method="post" action="../dept_search.cfm"><center>
-
<input name="search" type="text" />
-
<br />
-
<input type="submit" value="Department Search" />
-
</form>
And here is the query statement: - <cfquery name="search" datasource="dbname">
-
SELECT *
-
FROM dbtable
-
HAVING name LIKE '%#form.search#%'
-
OR description LIKE '%#form.search#%' OR keywords LIKE '%#form.search#%'
-
</cfquery>
Any ideas?
11 4918
Welcome to TSDN!
So you want to split the string and search for string1 or string2, i.e. if string1 or string2 appears in a record, it should be returned in the search? (not string1 AND string2)
Welcome to TSDN!
So you want to split the string and search for string1 or string2, i.e. if string1 or string2 appears in a record, it should be returned in the search? (not string1 AND string2)
I actually would like it to search for string1 AND string2. I'm just not sure of the best way to split it up and have each part run through a query. The splitting of the string is the biggest problem I am having.
I actually would like it to search for string1 AND string2. I'm just not sure of the best way to split it up and have each part run through a query. The splitting of the string is the biggest problem I am having.
I actually found something out that helped me. I changed my query to this: - <CFQUERY NAME="search" DATASOURCE="db">
-
SELECT *
-
FROM dbtable
-
WHERE(
-
<cfloop index="i" list="#form.search#" delimiters=" ">
-
<cfoutput>name LIKE '%#i#%' OR keywords LIKE '%#i#%' OR</cfoutput>
-
</cfloop>
-
'%%')
-
-
</CFQUERY>
This is working like a charm, the only thing is if I type something like "This is a wonderful day" the search is finding every term. For instance I only want it to find wonderful and day, but since I type the whole sentance it is also searching for is, a, and this. These are common words that I don't want it to find. Do you know anyway to have these not be searched for?
This is working like a charm, the only thing is if I type something like "This is a wonderful day" the search is finding every term. For instance I only want it to find wonderful and day, but since I type the whole sentance it is also searching for is, a, and this. These are common words that I don't want it to find. Do you know anyway to have these not be searched for?
Have a list of common words and if a particular search term matches then discard it. In your loop you could do a ListFind for each search term. If it doesn't match, then add the query string.
Could you possibly give me a code example of what you mean. Thank you.
Make a list of common words: - <cfset commonwords = "the,this,is,a,...">
Define a function that will search through the list and produce a new list, e.g. - <cfscript>
-
function removeCommon(lis) {
-
lis2 = "";
-
for (i=1; i lte listLen(lis); i=i+1) {
-
if(not listFindNoCase(commonwords,listGetAt(lis,i))) lis2 = lis2 & listGetAt(lis,i) & ",";
-
}
-
return lis2;
-
}
-
</cfscript>
-
I apologize for my ignorance, but I can't seem to get your code to work. Coldfusion just returns an error. I am copying directly from your code, of course removing the numbers, and it still doesn't work. I'm not sure what variables I am supposed to set. Thanks for any help.
What's the error message and on what line?
I couldn't tell you. The way the coldfusion that I am using is set up a default error page will come up to tell you something in coldfusion is broken. Just imagine how hard it is to develop in this environment. I can tell you that I getting the input from a form on a page then doing all my work on the next page. The list of words that I need to check would be form.search, or in coldfusion #form.search#. I just don't know where or how to add that piece to the code you've given me.
I guess to be more clear I should say: - <cfscript>
-
function removeCommon(lis) {
-
lis2 = "";
-
for (i=1; i lte listLen(lis); i=i+1) {
-
if(not listFindNoCase(commonwords,listGetAt(lis,i))) lis2 = lis2 & listGetAt(lis,i) & ",";
-
}
-
return lis2;
-
}
-
</cfscript>
-
Where do I put #form.search# which is my original string of words. Should I type <cfset #form.search# = lis> befor this code? Something like that? I hope this a little more clear. I really do appreciate all your help.
No, that is just a function called a UDF (user-defined function). You can use it like you would a built-in function.
Try: - <cfset newlist = removeCommon(form.search)>
Now newlist would contain the list of search items with the common words removed.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Mike |
last post by:
Looking to find any information on how to properly configure multiple
instances of DB2. This is on Win2k db2 ver 7.2. I am basically looking
for information on how the multiple instance settings...
|
by: dskillingstad |
last post by:
I'm trying to set up a parameter query based on an unbound form. This
search form has about 5 text boxes where the user can type in values
within each box and search a specific table based on the...
|
by: tshad |
last post by:
Can you do a search for more that one string in another string?
Something like:
someString.IndexOf("something1","something2","something3",0)
or would you have to do something like:
if...
|
by: James Radke |
last post by:
Hello,
I have a multithreaded windows NT service application (vb.net 2003) that I
am working on (my first one), which reads a message queue and creates
multiple threads to perform the processing...
|
by: Jesper Jensen |
last post by:
I have the following problem:
I have created the following SQL for my app. With the below shown code
(Example 1) I am able to retrieve the records I need into dataset
dsFind.
Now however I want...
|
by: serge |
last post by:
How can I run a single SP by asking multiple sales question either
by using the logical operator AND for all the questions; or using
the logical operator OR for all the questions. So it's always...
|
by: icfai |
last post by:
hi friends....
I have got a problem regarding loading of multiple assemblies, actually its required for an editor which implements the intellisenseas in vb or dotnet.
for that it is required to...
|
by: Bodyloss |
last post by:
Hey all
Ive ran into a bit of a problem when trying to parse multiple lines of javascript whitch are returned from an ajax request.
On the main page where the request orginates, i have a <div...
|
by: jmartmem |
last post by:
Greetings,
Perhaps someone can help me resolve what I hope is a simple dilemma...
I have one ASP page (TEST_RoadmapData_Search.asp) which contains two list/menus within a form, which, upon...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |