im building a tool to send out emails to my user base. I want to create a dialog where users can create clauses to filter the users they want to send to. I.e.
"User who registered before 08/08/15" - which is pretty easy to do in a mysql query
But I want to let the user combine clauses to further filter users. I.e.
"User who registered before 08/08/15" and
"User who of group 2"
My question is, what is the most efficient way to get the right users? It is pretty easy to translate those two example conditions into a mysql query, but I dont know how I can keep the query flexible to basically take unlimmited clauses to work.
Sth. like
$stmt = $mysqli->prepare("SELECT
id
FROM users
WHERE regDate > ?
AND usergroup = ?
");
But regDate and usergroup are variable ofcourse depending on what the users clause says.
So again, the question is not how to translate a clause into a query but more how I insert a various amount of "where" clauses into a query in a dynamic way. Basically how to integrate a variable amount of "AND" clauses in a prepared statement. Hope you understand^^