Solved

Search Criteria, Multiple Fields

Posted on 2010-11-17
2
365 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 500 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

Learn by Doing. Anytime. Anywhere.

Do you like to learn by doing?
Our labs and exercises give you the chance to do just that: Learn by performing actions on real environments.

Hands-on, scenario-based labs give you experience on real environments provided by us so you don't have to worry about breaking anything.

Question has a verified solution.

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

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
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 look for a specific file type in a local or remote server directory using PHP.

717 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