You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'or hijoID = ) AND cne_elecciones.gp = 0 Order by `cne_elecciones`.`fecha` A' at line 46