Genius_cd Posted August 25, 2009 Share Posted August 25, 2009 Hi, well i am new here.. i'm kind not bad in php but im stuck @ this.. i have a mysql table with field description table products +---+----------------+ | ID | description | +---+----------------+ |1 | Red | |2 | Liquered | |3 | Red,White | +---+----------------+ now i want to make a search with the term "red" $sql = mysql_query("SELECT * FROM products WHERE description LIKE '%red%' "); if i look inside the $sql the 3 rows are selected i want only the first and the last, how can i not integrate row 2 inside the sql search ?? the term red is inside Liquered , i dont want the sql (search) to select it ... please any help?? Link to comment https://forums.phpfreaks.com/topic/171760-search-for-a-specific-word-in-a-text/ Share on other sites More sharing options...
ToonMariner Posted August 25, 2009 Share Posted August 25, 2009 $sql = mysql_query("SELECT * FROM products WHERE description LIKE 'red%' "); if you want the field to start with the string red... Link to comment https://forums.phpfreaks.com/topic/171760-search-for-a-specific-word-in-a-text/#findComment-905686 Share on other sites More sharing options...
Genius_cd Posted August 25, 2009 Author Share Posted August 25, 2009 i tried it! not working for another word like redactive Link to comment https://forums.phpfreaks.com/topic/171760-search-for-a-specific-word-in-a-text/#findComment-905689 Share on other sites More sharing options...
Genius_cd Posted August 25, 2009 Author Share Posted August 25, 2009 Hi, well i am new here.. i'm kind not bad in php but im stuck @ this.. i have a mysql table with field description table products +---+----------------+ | ID | description | +---+----------------+ |1 | Red | |2 | Liquered | |3 | Red,White | +---+----------------+ now i want to make a search with the term "red" $sql = mysql_query("SELECT * FROM products WHERE description LIKE '%red%' "); if i look inside the $sql the 3 rows are selected i want only the first and the last, how can i not integrate row 2 inside the sql search ?? the term red is inside Liquered , i dont want the sql (search) to select it ... please any help?? ok and if i have redactive in row 4!! Hi, well i am new here.. i'm kind not bad in php but im stuck @ this.. i have a mysql table with field description table products +---+----------------+ | ID | description | +---+----------------+ |1 | Red | |2 | Liquered | |3 | Red,White | |4 | redActive | +---+----------------+ Link to comment https://forums.phpfreaks.com/topic/171760-search-for-a-specific-word-in-a-text/#findComment-905691 Share on other sites More sharing options...
thebadbad Posted August 25, 2009 Share Posted August 25, 2009 You can use regular expressions in the query, to only select rows where red appear without bounding word characters (using word boundaries): $sql = mysql_query("SELECT * FROM `products` WHERE `description` REGEXP '[[:<:]]red[[:>:]]'"); But I haven't actually seen that used before, so I'm not sure if it's inefficient or something. Link to comment https://forums.phpfreaks.com/topic/171760-search-for-a-specific-word-in-a-text/#findComment-905726 Share on other sites More sharing options...
Genius_cd Posted August 25, 2009 Author Share Posted August 25, 2009 I LOVE U!!!! thx thebadbad Link to comment https://forums.phpfreaks.com/topic/171760-search-for-a-specific-word-in-a-text/#findComment-905849 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.