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 '?page=2 AND let <> '1'' at line 3 SELECT COUNT(DISTINCT p.id) AS result_count FROM property p JOIN property_room r ON r.property_id = p.id JOIN landlord l ON l.id = p.landlord_id WHERE l.status = 'A' AND p.status = 'A' AND p.paid=1 AND l.id = ?page=2 AND let <> '1'