Mysql 1064语法错误

时间:2016-08-24 13:41:58

标签: mysql syntax-error

我收到了这个错误

错误号码:1064

您的SQL语法有错误;检查与MySQL服务器版本对应的手册,以便在' AND tbltickets.date>附近使用正确的语法。 DATE_SUB(now(),INTERVAL 3 MONTH)),tblstafftasks。`datea'在第1行

        $select = array(
            'tbltickets.ticketid',
            'subject',
            'tbltickets.date',
            'tbltickets.room_number',
            'tbltickets.guest_name',
            'tbldepartments.name',
            'tblservices.name'
        );

        $additionalSelect = array(
        'adminread',
        'tblstafftasks.id',
        'tblstafftasks.rel_id',
        'tblstafftasks.dateadded',
        'tblstafftasks.finished',
        'tbltickets.userid'
        );

        $join = array(
                    'LEFT JOIN tblservices ON tblservices.serviceid = tbltickets.service',
                    'LEFT JOIN tblstafftasks ON tblstafftasks.rel_id = tbltickets.ticketid AND tblstafftasks.rel_type = "ticket"',
                    'LEFT JOIN tbldepartments ON tbldepartments.departmentid = tbltickets.department'**strong text**
        );

        $where = array('AND status != 6');            

        if ($months_report != '') {
            $custom_date_select = '';
            if (is_numeric($months_report)) {
                $custom_date_select = 'AND date > DATE_SUB(now(), INTERVAL ' . $months_report . ' MONTH)';
            } else if ($months_report == 'custom') {
                $from_date = to_sql_date($_POST['report_from']);
                $to_date   = to_sql_date($_POST['report_to']);
                if ($from_date == $to_date) {
                    $custom_date_select = 'AND date = "' . $from_date . '"';
                } else {
                    $custom_date_select = 'AND (date BETWEEN "' . $from_date . '" AND "' . $to_date . '")';
                }
            }
            if ($custom_date_select != '') {
                $i = 0;
                foreach ($select as $_select) {
                    if ($i == 7) {
                        $_temp = substr($_select, 0, -1);
                        $_temp .= ' ' . $custom_date_select . ')';
                        $select[$i] = $_temp;
                    }
                    $i++;
                }
                array_push($where, $custom_date_select);
            }
        }

0 个答案:

没有答案