0

As you can see in the title, I have a table that I want to take use of in a website I have.

This is how the MySQL statement looks like now: SELECT * FROM bth_nav WHERE name LIKE (?) OR owner LIKE (?);

On my website I want to either search for name or owner. Right now I can only search for name but not owner. This is why I'm asking for help, I've tried to rewrite the statement but however I do it i can only search for one of them.

Thanks in advance.

Vao Tsun
  • 47,234
  • 13
  • 100
  • 132
kreqq_
  • 43
  • 1
  • 9

1 Answers1

1

The answer will be a little more complicated then you would expect.

I see question marks in your query, this way I can assume you're using prepared statements (which is good!).
Your old statement was using 1 value (for the name), and now you want to use 2.

You have some options for this to work.

The easiest one would be that you bind the value twice, but that's not the nicest way.

A better way would be to name your parameters, like this:

SELECT * FROM bth_nav WHERE name LIKE (:nameOwner) OR owner LIKE (:nameOwner);

Hence that I use the same name for both parameters here. Now you can bind the value to the named parameter with bindValue, and you need do this only once.

Blaatpraat
  • 2,829
  • 11
  • 23