MYSQL OR Statement Help

Posted on 2008-06-11
Medium Priority
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.
Question by:digarati
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 19

Accepted Solution

elimesika earned 200 total points
ID: 21760105

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

LVL 24

Assisted Solution

purplepomegranite earned 200 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


Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

777 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