Solved

MYSQL OR Statement Help

Posted on 2008-06-11
2
297 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Creating and Managing Databases with phpMyAdmin in cPanel.
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…
The viewer will learn how to count occurrences of each item in an array.

705 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now