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 '' at line 1 - SELECT id_seccion, id_bloque, titulo, slug, tipo, posicion, orden FROM bloques_x_seccion x LEFT JOIN imagenes i ON x.id_bloque=i.id_imagen WHERE tabla='corp_secciones' and id_seccion='' and x.posicion='derecha' order by posicion, orden, titulo