Skip to content
Advertisement

Search function on multiple rows in the same table

I’m wondering how do I add more row’s on my search script to be searched.

Here’s my php script:

As you can see this:

I want to it to search on region and rank rows. I tried:

…. it’s showing 0 results.

Thank you in advance.

Advertisement

Answer

Is this what you want?

This searches for the parameter in both columns region and rank.

Side notes:

  • For this to properly and consistently work, both columns must be of the same datatype

  • Use prepared statements! Do not concatenate variables in the query string; this is inefficient, and opens up your code to SQL injection. See How can I prevent SQL injection in PHP?

  • Starting version 8.0.2, rank is a reserved word in MySQL, hence not a good choice for a column name

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement