Brian Anderson wrote:
"IN ( exp1, exp2)" didn't seem to work for me. I've seen that used
before for including a subquery, but somehow it didn't like the comma
separated list.
I think this below is doing it for me.
$separated = implode("|", (explode(" ",
(AddSlashes($_REQUEST['terms'])))));
if($_REQUEST['c'] == "and"){
$conditional = 'AND';
}else{
$conditional = 'OR';
}
$delim = " WHERE Keyword REGEXP '$separated' $conditional
ItemDescription REGEXP '$separated'";
I'm still curious about the IN() keyword and how it works.
in() is good for id's:
select * from table where categoryid in (1,2,3,4,5);
it's basically expanded to an or:
select * from table where categoryid=1 or categoryid=2 or categoryid=3
or categoryid=4 or categoryid=5;
jblanchard@xxxxxxxxxx wrote:
[snip]
I am trying to simplify an SQL query that is pretty much like below:
$sql = "SELECT * FROM table WHERE keyword RLIKE '$expression1' OR
keyword RLIKE '$expression2' ";
The different terms '$expression1' and '$expression1' come from an
array.
Is there any way to within one regular expression to say either term1 or
term 2? Something like this where the OR condition would be basically
built into the regular expression:
$sql = "SELECT * FROM table WHERE keyword RLIKE '$expression'"; // the
$expression would have to signify either a or b.
Does that make sense?
[/snip]
Kinda'. If you asked on a SQL board they would say do this;
SELECT * FROM table WHERE keyword IN ($expression1, $expression2)
IN is the shorthand for multiple OR conditions.
--
Postgresql & php tutorials
http://www.designmagick.com/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php