?
Solved

Search Criteria, Multiple Fields

Posted on 2010-11-17
2
Medium Priority
?
366 Views
Last Modified: 2012-05-10
This code works fine, however, I can't seem to discover how to change it.  Right now, it pulls *everything from field_id127 and field_id_128 if either field_id127 or field_id_128 meet the search criteria.

WHAT I WANT to happen is, there will only be a return from a field if it matches the specific requirement, NOT IF either Or meet it. So, both may return a value if they meet the criteria, or one may only meet the criteria or maybe neither meet it and return 0.

$q = ("SELECT field_id_53, field_id_127, field_id_128 FROM exp_weblog_data WHERE
field_id_127 LIKE '%$gitcolor%' OR
field_id_128 LIKE '%$gitcolor%' OR
GROUP BY field_id_53")

Open in new window

0
Comment
Question by:rgranlund
[X]
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
2 Comments
 
LVL 8

Expert Comment

by:Kelvin81
ID: 34159382
I'm not too familiar with PHP

But if you need both conditions to be true, try using AND:

$q = ("SELECT field_id_53, field_id_127, field_id_128 FROM exp_weblog_data
WHERE
field_id_127 LIKE '%$gitcolor%'
AND field_id_128 LIKE '%$gitcolor%'
GROUP BY field_id_53")
0
 
LVL 58

Accepted Solution

by:
cyberkiwi earned 2000 total points
ID: 34159390
rgranlund,

With respect, still looking for samples.  This issue would have been sorted days ago if you just put up some samples.

Here is another answer based on another interpretation of your requirements:

$q = ("
SELECT
field_id_53,
Case when field_id_127 LIKE '%$gitcolor%' then field_id_127 else 0 end field_id_127,
Case when field_id_128 LIKE '%$gitcolor%' then field_id_128 else 0 end field_id_128
FROM exp_weblog_data
WHERE field_id_127 LIKE '%$gitcolor%' OR field_id_128 LIKE '%$gitcolor%' OR
GROUP BY field_id_53
")
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to dynamically set the form action using jQuery.
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 …
Suggested Courses

752 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