0

I have a php variable called industry, what i want to do is query that variable against the mysql database. However the mysql database has five columns in which that variable might be present, as indicated below.

industry ------> industry 1 industry 2 industry 3 industry 4 industry 5

below is my current php code.

     $query = "SELECT * FROM data where listing = 'rec' and industry='$industry'";

is there a way to query my php variable against all of the columns called industry?

2 Answers 2

1

I take your line "industry 1 industry 2 industry 3 industry 4 industry 5" means that there are five columns, named "industry1" through "industry5".

In this case you can combine the checks with an or operator.

SELECT * FROM data where listing = 'rec' and (industry1='$industry' or
  industry2='$industry' or industry3='$industry' or
  industry4='$industry' or industry5='$industry')
Sign up to request clarification or add additional context in comments.

Comments

0

You're going to have to chain together the different possibilities in your WHERE clause.

SELECT *
FROM   DATA
WHERE  LISTING = 'REC'
       AND (    INDUSTRY_1 = '$INDUSTRY'
             OR INDUSTRY_2 = '$INDUSTRY'
             OR INDUSTRY_3 = '$INDUSTRY'
             OR INDUSTRY_4 = '$INDUSTRY'
             OR INDUSTRY_5 = '$INDUSTRY');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.