Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Search Criteria, Multiple Fields

Posted on 2010-11-17
2
Medium Priority
?
368 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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

597 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