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 a.child= AND p.date BETWEEN '' AND '1969-12-31' GROUP BY a.id ORDER BY price' at line 3