Page 1 of 1

optional variables in a query

Posted: Thu Apr 20, 2006 9:32 am
by hame22
Hi

how do i include optional variables in a query

for example i want the query to return all rows where variable 1 is found in either field 1 OR field 2

the query i have at the moment looks like this

Code: Select all

$result = mysql_query("Select * from themes where related_theme1= '$theme_id' OR related_theme2 = '$theme_id");
obviously it is not working, any ideas how to fix it??

thanks in advance

Posted: Thu Apr 20, 2006 9:36 am
by JayBird
It looks okay to me, although you could try

Code: Select all

Select * from themes where (related_theme1= '$theme_id' OR related_theme2 = '$theme_id")

Posted: Thu Apr 20, 2006 9:50 am
by Ollie Saunders

Code: Select all

= '$theme_id");
missing single quote. should be

Code: Select all

= '$theme_id'");

Posted: Thu Apr 20, 2006 1:06 pm
by timvw

Code: Select all

SELECT foo
FROM bar
WHERE name IN ('john', 'mike', 'melissa')