0

On my site a user enters an account number and I have a script to show the business name belonging to that account number, however the account number could be in 2 columns.

I have the below code to search 1 of the columns (personID);

sql="SELECT * FROM member WHERE personID = '".$q."'";

How do I edit this code to search 2 columns (personID & another column) for the account number?

1
  • WHERE personId = 'something' OR other_column = 'something' Commented Jun 29, 2014 at 14:36

3 Answers 3

1

I believe the SQL OR is what you're looking for. Might be worth taking a look here http://www.w3schools.com/sql/sql_and_or.asp

sql="SELECT * FROM member WHERE personID = '".$q."' OR othercolumn = '".$q."'";
Sign up to request clarification or add additional context in comments.

Comments

0

Use OR:

sql="SELECT * FROM member WHERE personID = '".$q."' OR anotherColumn = '".$q."'";

Comments

0

You can do this with in:

sql="SELECT * FROM member WHERE '".$q."' IN (personID, othercol)"

The advantage of in is that the parameter is only mentioned once. This makes it easier to use proper parameters rather than string substitution -- a much better approach to generating SQL.

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.