user14679852
user14679852

Reputation:

How to add multiple dynamic WHERE queries?

I want to make a WHERE query with POST. A dynamic WHERE query is required when multiple query requests are received with POST.

I am using the PDOx repo. I want to pull data with multiple WHERE queries, but how can I do this? If it is not possible with PDOx, how can the classical (without any DB class) connection be made?

Sample;

$db->table('test')->where('active', 1)->getAll();
# Output: "SELECT * FROM test WHERE active='1'"

Upvotes: 0

Views: 60

Answers (1)

Maksim
Maksim

Reputation: 2957

You can add multiple where() on query object:

$query = $db->table('test');
if($_POST['one']){
  $query->where('field', $_POST['one'])
}
$result = $query->getAll();

Upvotes: 1

Related Questions