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 Link to comment https://forums.phpfreaks.com/topic/41024-retreiving-data-from-a-database/ 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. Link to comment https://forums.phpfreaks.com/topic/41024-retreiving-data-from-a-database/#findComment-198648 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? Link to comment https://forums.phpfreaks.com/topic/41024-retreiving-data-from-a-database/#findComment-198650 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. Link to comment https://forums.phpfreaks.com/topic/41024-retreiving-data-from-a-database/#findComment-198676 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 Link to comment https://forums.phpfreaks.com/topic/41024-retreiving-data-from-a-database/#findComment-198710 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. Link to comment https://forums.phpfreaks.com/topic/41024-retreiving-data-from-a-database/#findComment-198734 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????? Link to comment https://forums.phpfreaks.com/topic/41024-retreiving-data-from-a-database/#findComment-198775 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... Link to comment https://forums.phpfreaks.com/topic/41024-retreiving-data-from-a-database/#findComment-198783 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 Link to comment https://forums.phpfreaks.com/topic/41024-retreiving-data-from-a-database/#findComment-198814 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.