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 '?distance=0) GROUP BY `complex`.`id` ORDER BY `complex`.`sort` ASC' at line 1 [ SELECT `complex`.`id`, `complex`.`price`, `complex`.`price_one`, `complex`.`price_max`, `complex`.`metering_min`, `complex`.`metering_max`, `complex`.`status_construction`, `complex`.`number_flats`, `complex`.`reliable`, `complex`.`maps`, `complex`.`alias`, `complex`.`image`, `complex`.`image_logo`, `complex`.`image_layout`, `complex`.`top_price`, `complex`.`specifications`, `complex`.`specifications_param`, `complex`.`params_value`, `complex`.`check_maps`, `complex`.`premium`, `complex`.`individual_credit`, `complex`.`advertisement`, `complex`.`share_percentage`, `complex`.`stock_link`, `complex`.`show_ads`, `complex`.`promotion`, `complex`.`builder_alias`, `complex_i18n`.`address`, `complex_i18n`.`name`, `complex_i18n`.`stock_text` FROM `complex` JOIN `complex_i18n` ON (`complex`.`id` = `complex_i18n`.`row_id`) WHERE `complex_i18n`.`language` = 'ua' AND `complex`.`status` = 1 AND (`complex`.`distance` BETWEEN 0 and 10?distance=0) GROUP BY `complex`.`id` ORDER BY `complex`.`sort` ASC ]