ASP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingASP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old October 17th, 2002, 10:21 AM
aspnewbie aspnewbie is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: The Great White North
Posts: 361 aspnewbie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 58 m 50 sec
Reputation Power: 8
Send a message via MSN to aspnewbie
Searching More than One Field

Hi,

Is there a way in a SQL statement to search more than one field in a table. Here is my current code. It only searches the BODY field. I would like to be able to search the title and subtitle as well. Thanks in advance.

Code:

strSQL = "Select * from bv_PageSection " 
strSQL = strSQL & "WHERE SectionID=" & sID & " "
strSQL = strSQL & "AND Body LIKE "


	For item = 0 to UBound(objArray)
	 strSQL = strSQL & "'%" & objArray(item) & "%' "
	If item < UBound(objArray) Then
		strSQL = strSQL & " AND "
	End if
                Next

Reply With Quote
  #2  
Old October 17th, 2002, 12:49 PM
crazytrain81 crazytrain81 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 232 crazytrain81 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
SELECT * FROM table WHERE condition AND condition AND condition AND condition
etc..

Reply With Quote
  #3  
Old October 17th, 2002, 12:53 PM
crazytrain81 crazytrain81 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 232 crazytrain81 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
er missread your question sorry

what you are doing is essentially correct, I'm really not sure where you are having a problem. Your loop is only appending " AND " to your query as far as i can tell, and not adding a condition. Do a for each x in objArray.Fields , and then...

strSql = strSql & " AND body LIKE x.value AND subject LIKE x.value AND title LIKE x.value"

Reply With Quote
  #4  
Old October 17th, 2002, 01:08 PM
aspnewbie aspnewbie is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: The Great White North
Posts: 361 aspnewbie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 58 m 50 sec
Reputation Power: 8
Send a message via MSN to aspnewbie
The current loop is for the keywords entered in the search box. (I should have put in the full code).

So I guess what I should do is instead of saying "AND BODY ..."
I would do a count of the fields in my table, create an array of the field names then do a For i = 0 to objfieldsarray, get the field name, add an "OR"? , then use next to loop through the fields and the keywords?

I assume it would be an OR if I want it to look to see if it's in title, or in body or in subtitle (as opposed to requiring that it be in all three). How do I ensure that it is "WHERE SectionID" & sID AND the keyword appears in body, title or subtitle.

i.e. I want section 4 AND (body=keyword or title = keyword or subtitle = keyword)

NOT

section 4 and body = keyword OR title = keyword OR subtitle = keyword. (which would make the section 4 optional not mandatory)

Last edited by aspnewbie : October 17th, 2002 at 01:13 PM.

Reply With Quote
  #5  
Old October 18th, 2002, 09:10 PM
fakker fakker is offline
The calm b4 the storm
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Location: Manchester, UK
Posts: 404 fakker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Send a message via Yahoo to fakker
hhmm....

I think you could do something like:

PHP Code:
"SELECT * from bv_PageSection WHERE
(title LIKE '%keyword%' OR body LIKE '%keyword%' OR subtitle LIKE '%keyword%') AND sectionID = " 
sID  ""


I do not think you need to loop through the value from "keyword" as the LIKE clause will search for any words which might contain one of them...... I think?! forgive me if I'm wrong..... it's been a while since my SQL lessons!!
__________________
Matt 'Fakker' Facer

mattfacer.com

Reply With Quote
  #6  
Old October 18th, 2002, 09:15 PM
fakker fakker is offline
The calm b4 the storm
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Location: Manchester, UK
Posts: 404 fakker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Send a message via Yahoo to fakker
that's not meant to be PHP btw... I used the wrong code button!! lol!

Reply With Quote
  #7  
Old October 18th, 2002, 09:23 PM
aspnewbie aspnewbie is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: The Great White North
Posts: 361 aspnewbie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 58 m 50 sec
Reputation Power: 8
Send a message via MSN to aspnewbie
Thanks Matt,

I think I tried something similar and got a SQL syntax error statement, but I'll try it as you've set it out and see what happens. Hopefully it will work.

The loop was to get at the fact that the user might enter more than one keyword. It loops through all the keywords that the user entered, so I think I still need it, right? If the box was restricted to one term, then I wouldn't need the loop, but I like the idea that the user could enter a number of terms.

Reply With Quote
  #8  
Old October 18th, 2002, 09:29 PM
fakker fakker is offline
The calm b4 the storm
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Location: Manchester, UK
Posts: 404 fakker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Send a message via Yahoo to fakker
yeah, I quite agree that you need more than one keyword search.... but I thought that it would search each word seperately.... maybe not.....?

what was the exact SQL you used when you got the Syntax error.... if you post it we can help more on that!

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingASP Development > Searching More than One Field


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




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

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




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek