Подскажите почему возникает ошибка Notice: 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 'AND status = '1' ORDER BY review_id DESC LIMIT 0,20' at line 1
public function getreviews($data = array()) {
$sql = "SELECT * FROM " . DB_PREFIX . "review2";
if (!empty($data['filter_author'])) {
$sql .= " AND author LIKE '" . $this->db->escape($data['filter_author']) . "%'";
}
if (isset($data['filter_status']) && !is_null($data['filter_status'])) {
$sql .= " AND status = '" . (int)$data['filter_status'] . "'";
}
if (!empty($data['filter_date_added'])) {
$sql .= " AND DATE(date_added) = DATE('" . $this->db->escape($data['filter_date_added']) . "')";
}
$sort_data = array(
'pd.name',
'author',
'rating',
'status',
'date_added'
);
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
$sql .= " ORDER BY " . $data['sort'];
} else {
$sql .= " ORDER BY review_id";
}
if (isset($data['order']) && ($data['order'] == 'DESC')) {
$sql .= " DESC";
} else {
$sql .= " ASC";
}
if (isset($data['start']) || isset($data['limit'])) {
if ($data['start'] < 0) {
$data['start'] = 0;
}
if ($data['limit'] < 1) {
$data['limit'] = 20;
}
$sql .= " LIMIT " . (int) $data['start'] . "," . (int) $data['limit'];
}
$query = $this->db->query($sql);
return $query->rows;
}