Jump to content

[SOLVED] MYSQL Or Queries


iwpg

Recommended Posts

This is killing me. I know it should be simple, but I cannot get the statement to run.

 

$q = mysql_query("select * from db where item1 like '%$keyword%' or item2 like '%$keyword%' or item3 like '%$keyword%'");

 

Basically, the query is checking table 1,2 and 3 for the keyword, and returns the result if found.

 

Any help will be greatly remembered and appreciated.

 

Thanks,

 

Mike

Link to comment
https://forums.phpfreaks.com/topic/151695-solved-mysql-or-queries/
Share on other sites

Hi

 

Are you checking against several different tables?

 

If so then

 

$q = mysql_query("select * from table1 where item1 like '%$keyword%' UNION select * from table2 where item2 like '%$keyword%' UNION select * from table3 where item3 like '%$keyword%'");

 

All the best

 

Keith

Hi iwpg

 

Nothing immediately strikes me as wrong but in situations like this I try throwing in a few more brackets into the expression just to make it more explicit

 

$q = mysql_query("select * from db where (item1 like '%$keyword%') or (item2 like '%$keyword%') or (item3 like '%$keyword%') ");

 

The brackets may be surplus to requirements but I'd always rather have some surplus ones than not enough.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.