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 2646 CroCrew 564
Recognized Expert Contributor
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~
CroCrew 564
Recognized Expert Contributor
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?
CroCrew 564
Recognized Expert Contributor
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 ignore list or not.
I ran off and checked your ASPFAQ webby and I notice that Aaron still strips
them out, I was just wondering if this is the usual way to deal with that
search type, or whether there were good reasons when creating it to still...
|
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"
RegExp re = Word2;
if (re.Find(Word1))
|
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. Anybody have an idea of what I
need to add or change. It is the first If Then statement that I need to
search on partial matches. I've tried to use the like operator, but I just
get syntax errors.
If Not IsNothing(Me.LastName) Then
strSearch = "= "...
|
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, when you
press it it should generate search results in a new page.
However, when you click the "Generate Report" submit button, the moment
you try to THEN click the "Search" submit button, the "Search" submit
button NEVER goes to a new page but...
|
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 only shows content with "news report" instead of "news reporter"
I try to add a space to the keyword
i.e.
SELECT * FROM data WHERE content LIKE '* " + keyword + " '*;"
How ever this cannot search the keyword in the beginning of the content and...
| |
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 text='value'
|
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. This functionality is working
nicely and efficiently. I like this because I dont have to grab ALL the
records on each trip, just the next or previous 20. I am having a
terrible time creating the exact counts for the data grid navigation.
I use a...
|
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 short ) and are ignored. I have a need to search for those exact phrases - spaces included.
Thanks.
|
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 (in whole or as a substring) defined in file B. File B contains both the search string and the string it should be changed into.
Example file A
whippy
slippy
ippy
slippy
snoob
flop
bloppy
|
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 for Funky, and it comes up with all the hits.. I search for Funky Phantom, and it hangs for whatever
amount of seconds i have the script maximum execution time set to, then i get this error Fatal error: Maximum execution
time of 30 seconds...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |