Current location: Hot Scripts Forums » Programming Languages » PHP » how to use like clause this situation?


how to use like clause this situation?

Reply
  #1 (permalink)  
Old 03-31-05, 04:27 AM
weilies weilies is offline
Newbie Coder
 
Join Date: Apr 2004
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
how to use like clause this situation?

i encounter some prob in using a like clause

let say there are two records in a field:

- "One day, There a dog"
- "its name is sethere"

i want to use a where clause to select the first one but not return the second one, so i wrote something like

"select .... like '% ther%'

a space in front of the keyword "ther" intend to search something meaningful like in other situation, type in "test" hope to search for results like "test", "testing", "tested"... but not "abcdtest" bcoz the result is meaningless.

this sql string work well until encounter something like the keyword "ther" we wana search is the first word like

- "there is ...."

it wont return a result although it matched. i know what's wrong but hav no idea in how to consturct the sql statement...

i hope i make myself clear....
Reply With Quote
  #2 (permalink)  
Old 03-31-05, 05:52 AM
ben.periton ben.periton is offline
Wannabe Coder
 
Join Date: Oct 2004
Posts: 183
Thanks: 0
Thanked 0 Times in 0 Posts
If you only want to return test, testing etc but not abatest then use

...LIKE 'test%'.. with % at the end only.

% matches 0 or more chars, _ matches 1 char but can be used multiple times (so ... LIKE 'test___' ... would match testing but not tested as there are 3 underscores _ )

HTH
__________________
Ben Periton
http://ben.periton.co.uk
Reply With Quote
  #3 (permalink)  
Old 03-31-05, 06:12 AM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
What can I do about this horrible situation? ca_redwards General Advertisements 4 11-23-04 04:53 PM
where clause (AND / OR) Bantam PHP 0 09-30-04 05:40 AM
WHERE clause tbig ASP 3 07-28-04 02:03 PM
Complicated groupwise maximum / join query situation jove PHP 0 03-17-04 05:56 AM


All times are GMT -5. The time now is 05:39 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.