Jump to content

OR in a search query?


dmccabe

Recommended Posts

The answer is: using a LIKE clause with a % (which is an asterisk equivalent)

e.g.

SELECT * FROM `tbl_corpaccount` WHERE `accname` OR `accno` LIKE '$search%' ORDER BY aid ASC

 

I also noted another problem. Your logic is wrong.

"WHERE `accname` OR ..." will ALWAYS be true.

It needs to be "WHERE `accname` = 'blah' OR ..."

 

I have another question though, isn't `accno` going to be a number?

Link to comment
https://forums.phpfreaks.com/topic/98801-or-in-a-search-query/#findComment-505574
Share on other sites

Ok here is current code as I think we are confusing matters:

 

$query = "SELECT * FROM `tbl_corpaccount` WHERE `accname` OR `accno` LIKE '%$search%' ORDER BY aid ASC";

 

This doesnt work when I put it direct in to SQL query in phpmyadmin it returns 0 results.

 

however if I remove the OR `accno` section it works perfectly?

 

 

Link to comment
https://forums.phpfreaks.com/topic/98801-or-in-a-search-query/#findComment-505585
Share on other sites

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.