Invalid sql query : select * from tblimgcontrols JOIN imgfirmcategories ON imgfirmcategories.ImgControlRef = ImgControlID JOIN tblfirmcategory ON FirmCategoryRef = FirmCategoryID where ImgControlIsVisible != 0 and FirmCategoryRef = 79в€Ёdertype=desc and ImgBannerPlace = 'top_center' order by RAND() limit 1 === 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 '€Ёdertype=desc and ImgBannerPlace = 'top_center' order by RAND() limit ' at line 8