optional variables in a query

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
hame22
Forum Contributor
Posts: 214
Joined: Wed May 11, 2005 5:50 am

optional variables in a query

Post 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
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post 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")
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

Code: Select all

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

Code: Select all

= '$theme_id'");
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Code: Select all

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