Solved

MYSQL OR Statement Help

Posted on 2008-06-11
2
300 Views
Last Modified: 2013-12-13
$query = "select * from vendor where (businessname OR primarycontact OR estimatingcontact OR ownerofficercontact) like \"%$trimmed%\" order by businessname"; // EDIT HERE and specify your table and field names for the SQL query

I am new to using OR statements.
Is my syntax above correct, its returning no results.
If I do just businessname, I have results.
0
Comment
Question by:digarati
2 Comments
 
LVL 19

Accepted Solution

by:
elimesika earned 50 total points
ID: 21760105
HI

No, it is not correct , see code
 $query = "select * from vendor where (businessname like \"%$trimmed%\" OR primarycontact like \"%$trimmed%\" OR estimatingcontact like \"%$trimmed%\" OR like \"%$trimmed%\" ownerofficercontact) order by businessname"; // EDIT HERE and specify your table and field names for the SQL query

Open in new window

0
 
LVL 24

Assisted Solution

by:purplepomegranite
purplepomegranite earned 50 total points
ID: 21760110
You need to apply the condition to each field, as attached.
 $query = "select * from vendor where (businessname  like \"%$trimmed%\") OR (primarycontact  like \"%$trimmed%\") OR (estimatingcontact like \"%$trimmed%\") OR (ownerofficercontact like \"%$trimmed%\") order by businessname";

Open in new window

0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
wordpress on root is limiting my .htaccess 404.php options 4 30
php simple error message 4 24
PHP AJAX JSON 2 61
website maintenance mode 1 17
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question