npsari Posted March 3, 2007 Share Posted March 3, 2007 I have a Table (in my database) which consists of 3 Colombs Title: Story: Author: I know that if the Title is only 1 word, I use this code to retreive Data: SELECT * from $Tablename where (Title ='Word') However, what if the tittle is more than One word (With spaces)... Example: "The story of a brave man" How can the code match ANY of the words in the Title Quote Link to comment Share on other sites More sharing options...
Orio Posted March 3, 2007 Share Posted March 3, 2007 SELECT * FROM $Tablename WHERE Title LIKE '%Word%' This will match every title that contains the word "Word" Orio. Quote Link to comment Share on other sites More sharing options...
npsari Posted March 3, 2007 Author Share Posted March 3, 2007 Thanks ................ What if the Title has spaces? Example: The story of a brave man What will the code be? Quote Link to comment Share on other sites More sharing options...
Orio Posted March 3, 2007 Share Posted March 3, 2007 What do you mean? I think you mean this: SELECT * FROM $Tablename WHERE Title LIKE '%The story of a brave man%' This will match every title that has "The story of a brave man" in it. Quote Link to comment Share on other sites More sharing options...
npsari Posted March 3, 2007 Author Share Posted March 3, 2007 Hey, sorry if i confused you! I want the code to match any of the words So, if someone searched for "brave man" only (Not the whole exact tittle) He still gets the same result Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted March 3, 2007 Share Posted March 3, 2007 $query = "SELECT * FROM $Tablename WHERE Title LIKE '%{$word}%'"; this will search for $word in $Tablename. Quote Link to comment Share on other sites More sharing options...
npsari Posted March 3, 2007 Author Share Posted March 3, 2007 So, can $word be more than one word Can it be two words separated by spaces????? Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted March 3, 2007 Share Posted March 3, 2007 yes $word = "chocolate"; would match "chocolate cake", "chocolate biscuits with gravy", "dry chocolate biscuits", etc $word = "chocolate biscuits"; would match "chocolate biscuits with gravy", "dry chocolate biscuits", etc etc... Quote Link to comment Share on other sites More sharing options...
npsari Posted March 3, 2007 Author Share Posted March 3, 2007 Thank you that is what i was looking for good info Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.