-1

Is there any SQL syntax that allows you to search in many categories, like this:

Category array:

print_r($category) = Array ( [0] => 23 [1] => 24 [2] => 25 [3] => 26 [4] => 27 [5] => 28 [6] => 29 )

Code:

$tab = implode(' OR ', $category);        
$sql = "SELECT * FROM files WHERE name LIKE '%$what%' AND category = $tab ORDER BY name DESC LIMIT $from , $how_much";

1 Answers1

2

$sql = "SELECT * FROM files WHERE name LIKE '%$what%' AND category IN ($tab) ORDER BY name DESC LIMIT $from , $how_much";

You must use "IN".

I must add, if you don't use parameterized queries or PDO, you are open to sql injection vulnerability!

https://www.php.net/manual/en/pdo.prepared-statements.php

How can I prevent SQL injection in PHP?

Naveen Kumar
  • 160
  • 1
  • 10