PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP 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 February 16th, 2005, 09:45 PM
HowdeeDoodee HowdeeDoodee is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 14 HowdeeDoodee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 50 m 18 sec
Reputation Power: 0
[SOLVED] Need query string for exact string matches

I am using the following SELECT statement.

$query = "SELECT * FROM `View1` WHERE `Topic` LIKE '%$SeeAlso%'";

The statement pulls up all strings in the db because of the % operator.

Dumb question but how do I pull up exact matches even if the string is sitting next to the left or right border of a cell? I have tried removing the % operator but get no hits. In my db if I leave the % operator in the statement I get 130 hits but some hits are not exact. For example, if $SeeAlso = ed, I will get education, stuped, ed, edited, etc. How do I change the SELECT statement?

Reply With Quote
  #2  
Old February 17th, 2005, 09:03 AM
pmcnamee pmcnamee is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 13 pmcnamee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 12 m 52 sec
Reputation Power: 0
As long as you are using the % operator at the beginning and the end of your string to be searched then your result set will include all items that have the specified text anywhere in it.

What are you actually looking to return?

Reply With Quote
  #3  
Old February 17th, 2005, 03:17 PM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
If $SeeAlso isn't set, you will return all fields in the View1 table...

I think you're looking to return full words?

EXAMPLE:
ed would return...
but education/stuped/edited won't return...

Use Regular Expressions:
Code:
SELECT *
FROM table
WHERE fieldname REGEXP '[[:<:]](word)[[:>:]]'

this is untested and not guaranteed to work

Reply With Quote
  #4  
Old February 17th, 2005, 06:27 PM
HowdeeDoodee HowdeeDoodee is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 14 HowdeeDoodee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 50 m 18 sec
Reputation Power: 0
Thank you for the replies. If a user inputs the word "ed" in an input box or selects the word "ed" from a drop down list I want the user to find only those records with "ed" in the selected field. The fields to be searched are multi-word phrases so the phrase in a record may be something like "Special ed is underfunded" or "do not pick up Ed at work" or "Ed 101 is out of date" or "See the article on ed". The user selects terms to be searched or types in terms to be searched. Using the wildcard % operator I am currently selecting records that have any word with the two letters "ed" anywhere in the record including words with the letters within a word...not what I want. As I noted in my first post using the wildcard operator I am pulling up records with the words "education", "stuped", "ed", "edited", and so on when I want only "ed". If I use the = operator instead of the LIKE operator I get no records retrieved unless the field contains only the word or term selected which is also not what I want because every field to be searched contains phrases and not just one word. How do I change the SELECT statement to pick up a whole selected single words or whole selected phrases? Thank you again for the replies.

Reply With Quote
  #5  
Old February 17th, 2005, 06:32 PM
HowdeeDoodee HowdeeDoodee is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 14 HowdeeDoodee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 50 m 18 sec
Reputation Power: 0
MadCow, sorry I did not reply to your post. Thank you for the reply. I tried regexp but without the < and > qualifiers. I will give that a try and report back.

Reply With Quote
  #6  
Old February 17th, 2005, 06:59 PM
HowdeeDoodee HowdeeDoodee is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 14 HowdeeDoodee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 50 m 18 sec
Reputation Power: 0
MadCow, yu duh man.

Excellent!!!!!!

Working fine.

Thank you very much.

Reply With Quote
  #7  
Old February 18th, 2005, 07:45 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
The regular expression i posted will also match if the string is "I love my friend ed"
If that isn't what you want... you likely want a simple equals statement

Code:
SELECT *
FROM table
WHERE fieldname='word'

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > Need query string for exact string matches


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 6 hosted by Hostway