Solved

MYSQL OR Statement Help

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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Suggested Solutions

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…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

828 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