The query was unsuccessful. MySQL returned the following fatal error: 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 'ORDER BY `order` ASC' at line 1 And this was your query: SELECT * FROM images WHERE `type` = 'detail' && `pid` = ORDER BY `order` ASC ;