maltrecho
06-24-2003, 11:41 AM
In MySQL,when using REGEXP in a query, if I write 'word1|word2', the results will match all the rows containing ('word1' or 'word2'). What is the simplest way to match rows containing ('word1' and 'word2')?.
Example1:(...input type="... value="word1 or word2"... SUBMIT!)
Example2:(...input type="... value="word1 and word2"... SUBMIT!)
$keywords = stripslashes(trim($_GET['keywords']);
$keywords = str_replace(" or ", "|", $keywords); /* this one works great */
$keywords = str_replace(" and ", "???", $keywords); /* How to manage this one ??? */
$query = "SELECT name,
description
FROM table
WHERE ( (name REGEXP '$keywords')
OR (description REGEXP '$keywords') )";
The first one searches for 'word1' or 'word2' in all rows.
The second one should search for 'word'1 and 'word2' in the same row.
THANKS IN ADVANCED.
Example1:(...input type="... value="word1 or word2"... SUBMIT!)
Example2:(...input type="... value="word1 and word2"... SUBMIT!)
$keywords = stripslashes(trim($_GET['keywords']);
$keywords = str_replace(" or ", "|", $keywords); /* this one works great */
$keywords = str_replace(" and ", "???", $keywords); /* How to manage this one ??? */
$query = "SELECT name,
description
FROM table
WHERE ( (name REGEXP '$keywords')
OR (description REGEXP '$keywords') )";
The first one searches for 'word1' or 'word2' in all rows.
The second one should search for 'word'1 and 'word2' in the same row.
THANKS IN ADVANCED.