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 ') and d.direct > 0 and d.deal_groupID !=0 ' at line 18 SQL query : select d.id, d.name, d.description, d.companyID, d.address, d.cityID, d.price, d.full_price, d.deal_datetime, d.deal_groupID, d.image, '', '', '', d.companyID as company_id, d.sort_order, '', '', d.url as deal_url, '', d.votes, d.rating, '', '', '', '', d.add_date, '', d.views, d.clicks, d.full_description, d.supplier, d.percent, d.internalID, '', '', d.rating_plus, d.rating_minus, d.deal_subgroupID,'', d.direct, d.movedup, d.nostop from deals d where d.nostop=1 and d.cityID=2 and d.deal_datetime>=NOW() and ( ) and d.direct > 0 and d.deal_groupID !=0 order by DATE(d.add_date) desc, d.direct DESC, d.add_date desc, d.clicks desc limit 0, 30