Solved

Search Criteria, Multiple Fields

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Query 26 64
SQL: launch actions one before the other 10 23
Help Required 3 96
two ways encryption with php 3 26
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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 …

770 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