ASP Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreASP Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old July 10th, 2003, 09:42 AM
kmattera kmattera is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 4 kmattera User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question Need Search Form Field to look at multiple tables

Hi everyone,

I need to figure out if there is a way to allow users to be able to type in "keywords" into one search field and that search be performed on 2 different fields within one table.

Here is the code I am currently using:

**************************
'-Build dynamic sql
sql = "SELECT ContractID, URL, Vendor, VendorWebsite, Description, Keywords FROM Contracts WHERE ((General)=(Yes))"

'--ContractID (partial search)
If Not IsEmpty(Request("ContractID")) Then
Dim strContractID
strContractID = Trim(Request("ContractID"))

If strContractID <> "" Then
sql = sql & "AND (ContractID LIKE '%" & Replace(strContractID, "'", "''") & "%') "
End If
End If

***********************

This repeats for several other fields, and based on the input into the search form, the user gets their results. I have the code working as long as I'm not trying to combine 2 fields.

I'm sure its possible. I just don't know how to do it. Any help is GREATLY appreciated.

Thanks!

Kellie

Reply With Quote
  #2  
Old July 10th, 2003, 11:11 AM
kmattera kmattera is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 4 kmattera User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I think I figured it out....

I think I figured it out. Here's what I changed:

'--Keyword (partial search)
If Not IsEmpty(Request("Keywords")) Then
Dim strKeywords
strKeywords = Trim(Request("Keywords"))

If strKeywords <> "" Then
sql = sql & "AND (Keywords LIKE '%" & Replace(strKeywords, "'", "''") & "%' OR Description LIKE '%" & Replace(strKeywords, "'", "''") & "%') "
End If
End If
********************************

Problem is, if the user inputs keywords from both Keywords and Description field, no results are displayed. If user puts in only one keyword, it produces results. If I change the OR to AND, I get no results at all.

What the heck am I doing wrong here

Reply With Quote
  #3  
Old July 10th, 2003, 12:22 PM
OldJacques's Avatar
OldJacques OldJacques is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: in Orbit mostly
Posts: 148 OldJacques User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
multiple keywords

the problem is that when multiple keywords are inserted, the search is for an exact match of the phrase, which hardly ever exists.

You need to atomize the keywords (normally using either the space character, or one of the "boolean" characters) so that they are separated, and then create an even more "multiplied" SQL statement.

If the keywords field is filled in as "monkey elephant"
then you will need to generate the resulting SQL statement:
sql = sql & "AND (Keywords LIKE 'monkey' OR Keywords LIKE 'elephant' OR Description LIKE 'monkey'OR Description LIKE 'elephant') ", since you will probably never find "monkey elephant" in either the description or keywords fields together.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreASP Programming > Need Search Form Field to look at multiple tables


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway