CodeCharge Studio
search Register Login  

Visual PHP Web Development

Visually Create Internationalized Web Applications, Web Reports, Calendars, and more.
CodeCharge.com

YesSoftware Forums -> Archive -> GotoCode Archive

 Need Help to split search words. asp

Print topic Send  topic

Author Message
Michael
Posted: 08/13/2003, 2:46 AM

I need some help to adapt example below.

http://www.gotocode.com/art.asp?art_id=113&

I wish to know how to split my search words to increase results of searchs. Basically if someone types in two words it will do two seperate search etc...

I am useing codecharge 2 (not studio), ASP, MSAccess

The Article gives an example to download which I can get to work with the Bookstore Example but I can not get it to work on my site. The field I am searching is in is called "keywords" and from a table called "Details". Basically I changed the words name to keywords which didn't work. Please Help

The example code is below

Open event

if GetParam("name") <> "" then
string_to_split = GetParam("name")
tok = split(string_to_split, " ")
for i = 0 to ubound(tok) step 1
if i = 0 and i = ubound(tok) then
sWhere = sWhere & " and i.name like '%"& tok(i) &"%'"
elseif i = 0 then
sWhere = sWhere & " and (i.name like '%"& tok(i) &"%'"
elseif i = ubound(tok) then
sWhere = sWhere & " or i.name like '%"& tok(i) &"%')"
else
sWhere = sWhere & " or i.name like '%"& tok(i) &"%'"
end if
next
end if


BeforeShow event.

if GetParam("name") <> "" then
string_to_split = GetParam("name")
tok = split(string_to_split, " ")
for i = 0 to ubound(tok) step 1
fldname = replace(fldname, tok(i), "<font color = red>"& tok(i) &"</font>")
next
end if
rrodgers
Posted: 08/13/2003, 8:50 AM

>> Basically I changed the words name to keywords which didn't work. Please Help

What part didn't work? Any errors?

rob
Michael
Posted: 08/13/2003, 1:16 PM

This is the error message that I get when I change the code from
http://www.gotocode.com/art.asp?art_id=113& to match the field name that I am searching

Error Type:
Microsoft JET Database Engine (0x80040E14)
Syntax error in FROM clause.
/splitsearch/Common.asp, line 34

Michael
Posted: 08/13/2003, 1:30 PM

I thought that I should give more details of my problem.
This is the error Message that I get when I try to do a search (The page loads up ok, the problem is when I try to search)
Error Type:
Microsoft JET Database Engine (0x80040E14)
Syntax error in FROM clause.
/splitsearch/Common.asp, line 34
This is how I changed the code

(Open event of the result grid form)

if GetParam("keyword") <> "" then
string_to_split = GetParam("keyword")
tok = split(string_to_split, " ")
for i = 0 to ubound(tok) step 1
if i = 0 and i = ubound(tok) then
sWhere = sWhere & " and i.keyword like '%"& tok(i) &"%'"
elseif i = 0 then
sWhere = sWhere & " and (i.keyword like '%"& tok(i) &"%'"
elseif i = ubound(tok) then
sWhere = sWhere & " or i.keyword like '%"& tok(i) &"%')"
else
sWhere = sWhere & " or i.keyword like '%"& tok(i) &"%'"
end if
next
end if

(BeforeShow event of the result grid form)

if GetParam("keyword") <> "" then
string_to_split = GetParam("keyword")
tok = split(string_to_split, " ")
for i = 0 to ubound(tok) step 1
fldkeyword = replace(fldkeyword, tok(i), "<font color = red>"& tok(i) &"</font>")
next
end if
Michael
Posted: 08/15/2003, 11:02 PM

I can get the BeforeShow event to work and it highlights the search words but when I Put in the Open event code in that is when I get the problem. Has anybody had the same problem and how can I solve it.
Michael
Posted: 08/16/2003, 3:28 AM

The wonderfull Helen D from CodeCharge Support has helped me adapt split search / Hightlight function from http://www.gotocode.com/art.asp?art_id=113& There was three things that I had to change to make it work.

1. Anywhere that it said "name" I had to change it to the name of the field that I was searching i.e."keyword"

2. I had to change the i from i.name to match the first letter of the table that my searched field was in. In my case the table was called Details so i.name then became D.keyword

3. I had to assign any default value to sWhere at the very beginning of form Open event:
sWhere = " Where 1= 1 "

Below is the example that is given at http://www.gotocode.com/art.asp?art_id=113
(Open event of the result grid form)

if GetParam("name") <> "" then
string_to_split = GetParam("name")
tok = split(string_to_split, " ")
for i = 0 to ubound(tok) step 1
if i = 0 and i = ubound(tok) then
sWhere = sWhere & " and i.name like '%"& tok(i) &"%'"
elseif i = 0 then
sWhere = sWhere & " and (i.name like '%"& tok(i) &"%'"
elseif i = ubound(tok) then
sWhere = sWhere & " or i.name like '%"& tok(i) &"%')"
else
sWhere = sWhere & " or i.name like '%"& tok(i) &"%'"
end if
next
end if

and now is the example that Helen D helped me adapt
My table is called Details and my search field is keyword
(Add to Open event of the result grid form)

if GetParam("keyword") <> "" then
string_to_split = GetParam("keyword")
tok = split(string_to_split, " ")
for i = 0 to ubound(tok) step 1
if i = 0 and i = ubound(tok) then
sWhere = " Where 1= 1 "
sWhere = sWhere & " and D.keyword like '%"& tok(i) &"%'"
elseif i = 0 then
sWhere = sWhere & " and (D.keyword like '%"& tok(i) &"%'"
elseif i = ubound(tok) then
sWhere = sWhere & " or D.keyword like '%"& tok(i) &"%')"
else
sWhere = sWhere & " or D.keyword like '%"& tok(i) &"%'"
end if
next
end if


This seemed to work for me
Don't forget to include
sWhere = " Where 1= 1 "

Many thanks to Helen D
I hope that this can help somebody else.
I believe that if you get help to solve a problem you have, then you should post the fix to help someone else that may have the same problem.
Michael
Posted: 08/18/2003, 12:54 AM

In my previous post I put the
sWhere = " Where 1= 1 "
in the wrong place.
(This relates to spliting your search words to get greater results)
Below is the code in the the right order.
(Place this code in Open event)



if GetParam("keyword") <> "" then
string_to_split = GetParam("keyword")
sWhere = " Where 1= 1 "
tok = split(string_to_split, " ")
for i = 0 to ubound(tok) step 1
if i = 0 and i = ubound(tok) then
sWhere = sWhere & " and D.keyword like '%"& tok(i) &"%'"
elseif i = 0 then
sWhere = sWhere & " and (D.keyword like '%"& tok(i) &"%'"
elseif i = ubound(tok) then
sWhere = sWhere & " or D.keyword like '%"& tok(i) &"%')"
else
sWhere = sWhere & " or D.keyword like '%"& tok(i) &"%'"
end if
next
end if

   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Web Database

Join thousands of Web developers who build Web applications with minimal coding.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.