Jump to content

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.

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.