[Solved] Build dynamic WHERE clause in mySQL


Something like this?

$query .= "WHERE 
    1=1
    AND e.id=p.employee_id
    AND p.office_id=o.id
    AND (o.office_name="".mysqli_real_escape_string($officeName).""
        OR o.office_name="".mysqli_real_escape_string($firstName).""
        OR o.office_name="".mysqli_real_escape_string($lastName)."")
    ";

I used mysqli_real_escape_string() here as an example, you should use the correct and necessary precautions to avoid SQL injection in your system.

5

solved Build dynamic WHERE clause in mySQL