I have the following code that works very well, the problem is that of i search for say rap it returns back results that contain the words telegraph, grapfruit etc, how can i get it to just return results that have the word rap in the search string anywhere?? - <%
-
Dim strSearch, myarray, strSQL, strSQLExtra
-
If Not Request.Form("search") = "" Then
-
session("search") = Request.Form("search")
-
session("choice") = Request.Form("choice")
-
session("queryterm") = session("queryterm")+" "+Request.Form("search")
-
End If
-
-
'Loop is now in a function, so that we can feed it each field name.
-
Function addparams(fieldname,wordArray)
-
Dim tmp
-
tmp = ""
-
For each item in wordArray
-
tmp = tmp & " (" & fieldname & " Like '%" & item & "%') " & session("choice") & " "
-
next
-
tmp = left(tmp, len(tmp)-4) ' Chops off the last "AND "
-
addparams = tmp
-
End Function
-
-
'Build the word array
-
myarray = split(session("search"), " ")
-
-
'Build the SQL
-
strSQL = "SELECT * FROM mp3 INNER JOIN celebs ON mp3.celebid = celebs.idnumber WHERE ("
-
-
strSQL = strSQL & addparams("filename", myarray) ' change field one!
-
-
strSQL = strSQL & ") OR ("
-
-
strSQL = strSQL & addparams("mp3type", myarray) ' change field two!
-
-
strSQL = strSQL & ")order by surname, firstname, filename;"
-
session("sqlset") = strSQL
-
-
%>
4 2639
Hello colinod,
Here is an example that does what your looking to do. -
<%
-
Function WordFinder(FullString, WordToFind)
-
myarray = split(FullString)
-
For each item in myarray
-
If (item = WordToFind) Then
-
WordFinder = "Found!"
-
Exit Function
-
End If
-
next
-
WordFinder = "Not Found."
-
End Function
-
%>
-
<html>
-
<head>
-
<title>Test Page</title>
-
</head>
-
<body>
-
<%
-
If (Request.ServerVariables("REQUEST_METHOD") = "POST") Then
-
Response.Write("Looking for [" & Request.Form("xFind") & "]<br />")
-
Response.Write("In [" & Request.Form("xString") & "]<br />")
-
Response.Write(WordFinder(Request.Form("xString"), Request.Form("xFind")))
-
End If
-
%>
-
-
<form method="POST" name="xForm" action="Index.asp">
-
String: <input type="text" name="xString"><br />
-
Find this: <input type="text" name="xFind"><br />
-
<input type="Submit" name="xSubmit" value="Find">
-
</form>
-
</body>
-
</html>
-
Hope it helps,
CroCrew~
in the first box type in "Hello how are you today Michelle" and the second box type in "to". There should be no matches.
then for the second test:
in the first box type in "Hello how are you today Michelle" and the second box type in "today". There should be a match now.
Hope that that helped you out,
CroCrew~
Hi thanks for that but i am trying to do this with sql in an asp page, am i in the wrong place for this question?
Hello Colinod,
I think you'd have to search for '% rap %' and include the spaces in the search. Like this: -
SELECT * FROM [table] WHERE (([field] LIKE '% rap %') OR ([field] LIKE '% rap%') OR ([field] LIKE '%rap %'))
-
Hope that helps,
CroCrew~
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Rob Meade |
last post by:
Lo all,
I was just running through some code I was writing for a site and when it
came to the 'exact phrase' search type I wasn't sure whether that should run
through and ignore the words in the...
|
by: Mark Findlay |
last post by:
I am trying to figure out how to set up my reg exp search so that the search
will only match on the exact word.
Here is the current problem code:
Word1 = "RealPlayer.exe"
Word2 = "Player.exe"...
|
by: Larry |
last post by:
I have the following code attached to a search button on a form that runs a
query. It works great, except that the search for Last Name only returns
exact matches. It is even case sensitive....
|
by: comp.lang.php |
last post by:
I have a form that when you click the "Generate Report" submit button,
it will force download a CSV file, required for this project.
On the very same page you also have a "Search" submit button,...
|
by: Kwok |
last post by:
I want to search a keyword in a content stored in a table, which the content is a abstract of a report
I want to search a keyword by exact word such as:
User input : news report
The result will...
|
by: jmdaviault |
last post by:
I want to do the equivalent of
SELECT id from TABLE WHERE text='text'
only fast solution I found is:
SELECT id,text from TABLE WHERE MATCH(text) AGAINST('value' IN BOOLEAN
MODE) HAVING...
|
by: dbarker1 |
last post by:
Hello All,
I am developing a web front end using the standard datagrid in the 1.1
framework. Currently it allows users to navigate through records 20 at
a time via previous and next buttons. ...
|
by: Cli |
last post by:
Is it possible to search for exact phrases which include a digit. e.g. "Dublin 1" vrs "Dublin 2" using Mysql fulltext search?
As far as I can tell the digits are considered stop words ( too...
|
by: Slippy27 |
last post by:
I'm trying to modify a find/replace script which iterates through a file A and makes replacements defined in a csv file B. My original goal was to change any line in file A containing a search string...
|
by: Rilly |
last post by:
Anyone use PowerMovielist here? I have the 0.14 beta version.
Do you have a problem where some shows you search for cause the fetch to hang ? I'm pulling my hair out on this..
For example, I search...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
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: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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: 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: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |