You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ') AND (p.type = 1 OR p.type = 2 OR p.type = 3) AND ' at line 16, 1176