473,394 Members | 1,852 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Multiple Search Parameters

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.
Expand|Select|Wrap|Line Numbers
  1. <form method="post" action="../dept_search.cfm"><center>
  2. <input name="search" type="text" />
  3. <br />
  4. <input type="submit" value="Department Search" />
  5. </form>
And here is the query statement:
Expand|Select|Wrap|Line Numbers
  1. <cfquery name="search" datasource="dbname">
  2.             SELECT * 
  3.             FROM dbtable
  4.             HAVING name LIKE '%#form.search#%'
  5.             OR description LIKE '%#form.search#%' OR keywords LIKE '%#form.search#%'
  6.         </cfquery>
Any ideas?
May 31 '07 #1
11 4918
acoder
16,027 Expert Mod 8TB
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)
Jun 1 '07 #2
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.
Jun 1 '07 #3
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:
Expand|Select|Wrap|Line Numbers
  1. <CFQUERY NAME="search" DATASOURCE="db">
  2.     SELECT *
  3.     FROM dbtable
  4.     WHERE(
  5.     <cfloop index="i" list="#form.search#" delimiters=" ">
  6.         <cfoutput>name LIKE '%#i#%' OR keywords LIKE '%#i#%' OR</cfoutput>
  7.     </cfloop>
  8.     '%%')
  9.  
  10. </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?
Jun 1 '07 #4
acoder
16,027 Expert Mod 8TB
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.
Jun 1 '07 #5
Could you possibly give me a code example of what you mean. Thank you.
Jun 4 '07 #6
acoder
16,027 Expert Mod 8TB
Make a list of common words:
Expand|Select|Wrap|Line Numbers
  1. <cfset commonwords = "the,this,is,a,...">
Define a function that will search through the list and produce a new list, e.g.
Expand|Select|Wrap|Line Numbers
  1. <cfscript>
  2. function removeCommon(lis) {
  3.     lis2 = "";
  4.     for (i=1; i lte listLen(lis); i=i+1) {
  5.         if(not listFindNoCase(commonwords,listGetAt(lis,i))) lis2 = lis2 & listGetAt(lis,i) & ",";
  6.     }
  7.     return lis2;
  8. }
  9. </cfscript>
  10.  
Jun 5 '07 #7
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.
Jun 18 '07 #8
acoder
16,027 Expert Mod 8TB
What's the error message and on what line?
Jun 19 '07 #9
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.
Jun 19 '07 #10
I guess to be more clear I should say:

Expand|Select|Wrap|Line Numbers
  1.       <cfscript>
  2.       function removeCommon(lis) {
  3.           lis2 = "";
  4.           for (i=1; i lte listLen(lis); i=i+1) {
  5.               if(not listFindNoCase(commonwords,listGetAt(lis,i))) lis2 = lis2 & listGetAt(lis,i) & ",";
  6.           }
  7.           return lis2;
  8.       }
  9.       </cfscript>
  10.  
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.
Jun 19 '07 #11
acoder
16,027 Expert Mod 8TB
No, that is just a function called a UDF (user-defined function). You can use it like you would a built-in function.

Try:
Expand|Select|Wrap|Line Numbers
  1. <cfset newlist = removeCommon(form.search)>
Now newlist would contain the list of search items with the common words removed.
Jun 19 '07 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

11
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...
2
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...
32
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...
6
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...
3
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...
7
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...
1
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...
3
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...
9
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
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...
0
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...
0
Oralloy
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,...
0
jinu1996
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...
0
tracyyun
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.