PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

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:
  #1  
Old May 7th, 2009, 06:43 AM
grissom grissom is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 47 grissom User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 h 18 m 17 sec
Reputation Power: 5
Search for multiple words within one field

I have a test database with filenames, images and keywords etc. The keyword field contains several keywords, like Cruiseskip vestlandet Cruisebåt Cruiseskip Cruiseskip Flåm Cruiseskip vestlandet Skip Båt. When searching for two words that follow eachother I get a result but when searching for two or more words within the keyword field that do not follow directly after eachother I get no result.

I also need to be able to get a result from multiple keywordfields, like one image has Cruiseship as a keyword, another image has River as a keyword, if I search for both these words I get no result and I want to retreive both images.

My SQL looks like this.

rsImages_cmd.CommandText = "SELECT Name, Keywords FROM Kalimages WHERE Keywords LIKE'%" & strSearch & "%'" & "OR Name LIKE'%" & strSearch & "%'"

The code for the entire page

Link to live page

Any help would be appreciated.

Reply With Quote
  #2  
Old May 7th, 2009, 08:11 AM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 20,687 r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 1 Week 3 Days 9 h 27 m 54 sec
Reputation Power: 2458
you want to search "for two or more words within the keyword field"

you need something like this --
Code:
WHERE Keywords LIKE '%word1%' AND Keywords LIKE '%word2%'
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book

Reply With Quote
  #3  
Old May 7th, 2009, 02:20 PM
grissom grissom is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 47 grissom User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 h 18 m 17 sec
Reputation Power: 5
Quote:
Originally Posted by r937
you want to search "for two or more words within the keyword field"

you need something like this --
Code:
WHERE Keywords LIKE '%word1%' AND Keywords LIKE '%word2%'


I tried using AND but this returned no results.

Reply With Quote
  #4  
Old May 7th, 2009, 02:23 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 20,687 r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 1 Week 3 Days 9 h 27 m 54 sec
Reputation Power: 2458
Quote:
Originally Posted by grissom
I tried using AND but this returned no results.
this would indicate that there are no rows that satisfy the criterion of having both of the words you searched for


Reply With Quote
  #5  
Old May 7th, 2009, 05:52 PM
grissom grissom is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 47 grissom User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 h 18 m 17 sec
Reputation Power: 5
Quote:
Originally Posted by r937
this would indicate that there are no rows that satisfy the criterion of having both of the words you searched for



I tried removing the last part of the SQL statement, the SQL would the look like this - "SELECT Keywords FROM Kalimages WHERE Keywords LIKE'%" & strSearch & "%'" - but it made no difference. Searching for two or more words that do not directly follow eachother in the keyword field gave no result.

Reply With Quote
  #6  
Old May 7th, 2009, 06:48 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 20,687 r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 1 Week 3 Days 9 h 27 m 54 sec
Reputation Power: 2458
do me a favour, please test the query outside of php first

just to restore your confidence in SQL


Reply With Quote
  #7  
Old May 8th, 2009, 09:18 AM
grissom grissom is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 47 grissom User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 h 18 m 17 sec
Reputation Power: 5
Quote:
Originally Posted by r937
do me a favour, please test the query outside of php first

just to restore your confidence in SQL



I've found no fault in the SQL statement, but I think I need to do some sort of split function when using multiple keywords. It's been a while since i've done this, but I'll do some testing.

Reply With Quote
  #8  
Old May 8th, 2009, 09:20 AM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 20,687 r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 1 Week 3 Days 9 h 27 m 54 sec
Reputation Power: 2458
since there is no fault in the SQL, i'll move this thread to the php forum

Reply With Quote
  #9  
Old May 8th, 2009, 09:40 AM
ManiacDan's Avatar
ManiacDan ManiacDan is offline
User, Contributing
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Oct 2006
Location: Texas, USA
Posts: 3,776 ManiacDan User rank is General 11st Grade (Above 100000 Reputation Level)ManiacDan User rank is General 11st Grade (Above 100000 Reputation Level)ManiacDan User rank is General 11st Grade (Above 100000 Reputation Level)ManiacDan User rank is General 11st Grade (Above 100000 Reputation Level)ManiacDan User rank is General 11st Grade (Above 100000 Reputation Level)ManiacDan User rank is General 11st Grade (Above 100000 Reputation Level)ManiacDan User rank is General 11st Grade (Above 100000 Reputation Level)ManiacDan User rank is General 11st Grade (Above 100000 Reputation Level)ManiacDan User rank is General 11st Grade (Above 100000 Reputation Level)ManiacDan User rank is General 11st Grade (Above 100000 Reputation Level)ManiacDan User rank is General 11st Grade (Above 100000 Reputation Level)ManiacDan User rank is General 11st Grade (Above 100000 Reputation Level)ManiacDan User rank is General 11st Grade (Above 100000 Reputation Level)ManiacDan User rank is General 11st Grade (Above 100000 Reputation Level)ManiacDan User rank is General 11st Grade (Above 100000 Reputation Level)ManiacDan User rank is General 11st Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 19 h 31 m 26 sec
Reputation Power: 1677
He's using VB Script (ugh) so we should probably move the thread again.

-Dan
__________________
"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

"The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

Think we're being rude? Please read this. Trying to argue intelligently? Please read this.

Reply With Quote
  #10  
Old May 8th, 2009, 12:01 PM
grissom grissom is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 47 grissom User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 h 18 m 17 sec
Reputation Power: 5
Quote:
Originally Posted by ManiacDan
He's using VB Script (ugh) so we should probably move the thread again.

-Dan


I am using ASP and VBScript. Feel free to move the thread to where it correctly belongs. Sorry for posting in the wrong forum.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Search for multiple words within 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.

 
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.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
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.

 
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.

 

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




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
Stay green...Green IT