codeigniter SQL出现503错误

时间:2018-04-10 08:16:37

标签: php codeigniter codeigniter-3

我目前正在为我系统中存储的一些数据构建报告,但我遇到了一些问题。更改我的一个函数后,我一直收到503错误,以便为我的客户端获取正确的数据。

我的报告正在做的是循环一组中心并为每个中心获取大量数据。用于所述小中心的每个数据位。我曾经使用以下功能获得注册商店:

private function get_stores( $start, $end, $centreid ) {

    $store_gids = array();

    $this->db->select( 'id,IF(kpi_group_name="",name,kpi_group_name) AS name,retailer_staff,retailer_sm,kpi_group' );
    $this->db->from( ' groups AS g ' );
    $this->db->where( 'g.id > 0' );
    $this->db->where( '(retailer_staff = 1 OR retailer_sm = 1 OR kpi_group > 0)' );
    $this->db->where( 'centreid', $centreid );
    $this->db->group_by( ' retailer_staff,retailer_sm,kpi_group' );
    $data = $this->db->get();
    $data = $data->result_array();

    if ( count( $data ) > 0 ) {
        foreach ( $data as $g ) {
            if ( $g['retailer_sm'] == 1 ) {
                $store_gids[] = $g['id'];
            }
            if ( $g['retailer_staff'] == 1 ) {
                $store_gids[] = $g['id'];
            }
        }
    }


    $this->db->select( 'l.id ' );
    $this->db->from( ' local_orgs AS l ' );
    $this->db->join( 'local_groups as lg', 'l.id=lg.localid' );
    $this->db->where( 'l.id > 0' );
    $this->db->where( 'l.deleted=0' );
    $this->db->where( 'l.centreid=', $centreid );

    if ( ! empty( $store_gids ) ) {
        $this->db->where( 'lg.groupid IN (' . implode( ",", $store_gids ) . ')' );
    }

    if ( ! empty( $end ) ) {
        $this->db->where( 'l.createddate <=', date( "Y-m-d H:i:s", strtotime( $end ) ) );
    }

    $this->db->group_by( 'l.id' );
    $query = $this->db->get();

    return count( $query->result_array() );
}

然而,获得的数据不正确,因此更改为:

    private function get_stores_2( $start, $end, $centreid ) {
    log_message('info', "centreid = " . $centreid . ": MEMORY: " .  memory_get_usage ( ). ": LIMIT: " .  ini_get('memory_limit') . " : " . ini_get('max_execution_time'));
    $gids       = array();


    $this->db->select( 'id' );
    $this->db->from( ' groups AS g  ' );
    $this->db->where( 'g.id > 0 ' );
    $this->db->where( '(retailer_staff = 1 OR retailer_sm = 1 OR kpi_group > 0) ' );
    $this->db->where( 'centreid', $centreid );
    $this->db->group_by( 'retailer_staff,retailer_sm,kpi_group' );
    $data = $this->db->get()->result_array();
    $this->db->flush_cache();

    if ( count( $data ) > 0 ) {
        foreach ( $data as $g ) {
            $gids[] = $g['id'];
        }
    }
    unset( $data );


    if(empty($end)) {
        $end = date("Y-m-d H:i:s", time());
    }


    $this->db->select( 'COUNT(`hd1`.`localid`) OVER () as "count"' );
    $this->db->from( ' history_devices AS hd1 ' );
    $this->db->join( sprintf( '(SELECT MAX(hd1.id) AS maxid 
FROM history_devices AS hd1 
LEFT JOIN local_groups AS lg ON (hd1.localid=lg.localid) AND hd1.roleid=lg.roleid 
LEFT JOIN local_orgs AS l ON (hd1.localid=l.id) 
WHERE hd1.id > 0 
AND l.deleted = 0 
AND hd1.centreid = %d 
AND hd1.createddate <= \'%s\' 
AND lg.groupid IN (%s)  
AND hd1.profileid > 0 
GROUP BY hd1.profileid) AS hd2 ', $centreid, date( "Y-m-d H:i:s", strtotime( $end ) ), implode( ',', $gids ) ), 'hd1.id=hd2.maxid', 'left' );

    unset($gids);
    $this->db->join('local_groups AS lg', 'hd1.localid=lg.localid AND hd1.roleid=lg.roleid', 'left');

    $this->db->where( 'hd1.id > 0' );
    $this->db->where( 'hd2.maxid IS NOT NULL' );
    $this->db->where( 'hd1.statusid != 4' );
    $this->db->where( 'hd1.profileid > 0' );
    $this->db->where( 'hd1.centreid', $centreid );
    $this->db->group_by( ' hd1.localid' );
    $this->db->limit( 1 );

    $data = $this->db->get()->row();

    return $data->count;

}

然而,第二个函数在运行几个不同的中心后返回503错误。我可以告诉你,也没有内存问题或php执行时间限制。所以我对如何修复它并不感到难过。

如果它有任何帮助,我的整个模型看起来像这样:

<?php

class Benchmarking_m extends CI_Model {

    private $_centreid = 0;
    private $_appid = 0;

    public function __construct() {
        parent::__construct();
        set_time_limit ( 1000 );
        $this->_centreid = (int) cms_user( 'centreid' );
        $this->_appid    = (int) centre( 'appid' );

    }

    public function create_new_manual( $args ) {

        $insert = array(
            'centreid'   => $this->_centreid,
            'data'       => serialize( $args ),
            'cms_userid' => cms_user( 'userid' )
        );

        return $this->db->insert( 'benchmark_manual_data', $insert );
    }

    public function get_manual( $args ) {
        $this->db->select( '*' );
        $this->db->from( 'benchmark_manual_data' );
        $this->db->where( 'centreid', $this->_centreid );
        $results = $this->db->get();

        return $results->result_array();
    }

    public function get_manual_recent( $args ) {
        $this->db->select( '*' );
        $this->db->from( 'benchmark_manual_data' );
        $this->db->where( 'centreid', $this->_centreid );
        $this->db->order_by( 'id', 'desc' );
        $this->db->limit( 1 );
        $results = $this->db->get();

        return $results->result_array();
    }

    public function get_manual_between_centreid( $startdate, $enddate, $centreid ) {
        $this->db->select( '*' );
        $this->db->from( 'benchmark_manual_data' );
        $this->db->where( 'centreid', $centreid );

        $this->db->order_by( 'createdate', 'desc' );
        $this->db->limit( 1 );

        $results = $this->db->get()->result_array();

        return $results;
    }


    public function generate_report( $args = array() ) {


        $this->load->model( 'centres_m' );

        $rows = array();

        $centres = $this->centres_m->get_all_centres_by_app_id( $this->_appid,true );
//      printr($centres);
        ini_set( 'memory_limit', "-1" );
        set_time_limit(0);
        $this->db->save_queries = false;

        foreach ( $centres as $index => $centre ) {
            $rows[] = $this->report_centre_row( $centre['id'], $centre['name'] );
            unset( $centres[ $index ] );
            clearstatcache();
        }


        $this->load->helper( 'excel' );
//
        excel_sheet(  array(
                          'Country',
                          'Shopping Centre Name',
                          'Launch Date',
                          'Total Stores',
                          'Enrolled Stores',
                          'Total Staff',

                          'Enrolled Staff',
                          'Active users',

                          'Candidates Sales',
                          'Uploaded Sales',
                          'Discounts',
                          'Job Offers',
                          'Access To Centre Requests',
                          'Maintenance',
                          'Cleaning',
                          'Security',
                          'Reverse Ticketing',
                          'Total Tickets',
                          'Ticketing',
                          'News',
                          'Job Offers (Hits)',
                          'KPIs',
                          'Marketing',
                          'Staff Offers',
                          'Documents',
                          'Contact us',
                          'Team management',

                          'Total Hits',

                          'Average completion time of tickets (hours)',

                          'Audit Car park',
                          'Audit Entrance',
                          'Audit Mall',
                          'Audit Reception Desk',
                          'Audit Rest Area',
                          'Audit Toilets',

                          'Sum of reports created'
                      ), $rows );

    }

    private function report_centre_row( $id, $name ) {
        $this->load->model( 'categories_m' );
        $this->load->model( 'profiles_m' );
        $this->load->model( 'Analytics_m' );
        $row = array();


        $data = $this->get_manual_between_centreid( $_POST['startdate'], $_POST['enddate'], $id );

        if ( ! empty( $data[0]['data'] ) ) {
            $data = unserialize( $data[0]['data'] );
        } else {
            $data = array();
        }


        $activeUser = $this->get_active_users_centreid( $id, $_POST['startdate'], $_POST['enddate'] );/**
         * This and down i am trying to save on as much memory as possible
         */;

        $row = array(
            $data['country'],
            $name,
            $data['launch_month'] . "-" . $data['launch_year'],
            $data['Total_Stores'],
            $this->get_stores_2( $_POST['startdate'], $_POST['enddate'], $id ),
            # Enrolled Stores
            $data['Total_Staff'],

            $this->profiles_m->get_profiles_by_centreid( $id, array(
                "enddate" => $_POST['enddate'],
            ) ),
            # Enrolled Staff
            $activeUser,

            "",
            "",
            $this->get_stream_count_by_category_type_endDate( 11, $id, NULL, $_POST['enddate'] )[0]->total,
            #Total Discounts
            $this->get_stream_count_by_category_type_endDate( 12, $id, NULL, $_POST['enddate'] )[0]->total,
            #Job Offers
        );
        unset( $data );

        //Total tickets
        $access_To_Centre_Requests = $this->get_stream_count_by_ticket_type( 13, $id, $_POST['startdate'], $_POST['enddate'] )[0]->total;
        $maintenance               = $this->get_stream_count_by_ticket_type( 3, $id, $_POST['startdate'], $_POST['enddate'] )[0]->total;
        $cleaning                  = $this->get_stream_count_by_ticket_type( 4, $id, $_POST['startdate'], $_POST['enddate'] )[0]->total;
        $Security                  = $this->get_stream_count_by_ticket_type( 5, $id, $_POST['startdate'], $_POST['enddate'] )[0]->total;
        $ReverseTicketing          = $this->get_stream_count_by_ticket_type( 21, $id, $_POST['startdate'], $_POST['enddate'] )[0]->total;

        $row = array_merge( $row, array(
            $access_To_Centre_Requests,
            $maintenance,
            $cleaning,
            $Security,
            $ReverseTicketing,
            ( $access_To_Centre_Requests + $maintenance + $cleaning + $Security + $ReverseTicketing ),
        ) );
        unset( $access_To_Centre_Requests, $maintenance, $cleaning, $Security, $ReverseTicketing );

        //Total hits per category
        $Ticketing       = $this->get_total_category_views_by_centre( 6, $id, $_POST['startdate'], $_POST['enddate'] );
        $news            = $this->get_total_category_views_by_centre( 2, $id, $_POST['startdate'], $_POST['enddate'] );
        $jobOfferHits    = $this->get_total_category_views_by_centre( 12, $id, $_POST['startdate'], $_POST['enddate'] );
        $kpis            = $this->get_total_category_views_by_centre( 7, $id, $_POST['startdate'], $_POST['enddate'] );
        $marketing       = $this->get_total_category_views_by_centre( 1, $id, $_POST['startdate'], $_POST['enddate'] );
        $Staff_Offers    = $this->get_total_category_views_by_centre( 8, $id, $_POST['startdate'], $_POST['enddate'] );
        $documents       = $this->get_total_category_views_by_centre( 9, $id, $_POST['startdate'], $_POST['enddate'] );
        $contactus       = $this->get_total_category_views_by_centre( 10, $id, $_POST['startdate'], $_POST['enddate'] );
        $Team_management = $this->get_total_category_views_by_centre( 14, $id, $_POST['startdate'], $_POST['enddate'] );
        $ave_time_diff_c = $this->get_tickets_average_hours( $id, $_POST['startdate'], $_POST['enddate'] );

        $row = array_merge( $row, array(
            $Ticketing,
            $news,
            $jobOfferHits,
            $kpis,
            $marketing,
            $Staff_Offers,
            $documents,
            $contactus,
            $Team_management,
            ( $Ticketing + $news + $kpis + $marketing + $Staff_Offers + $documents + $contactus + $Team_management + $jobOfferHits ),
            $ave_time_diff_c
        ) );
        unset( $Ticketing, $news, $kpis, $marketing, $Staff_Offers, $documents, $contactus, $Team_management, $ave_time_diff_c, $jobOfferHits );

        //Audit Form Counting
        $Audit_Car_park       = $this->get_stream_count_by_category_type( 15, $id, $_POST['startdate'], $_POST['enddate'] )[0]->total;
        $Audit_Entrance       = $this->get_stream_count_by_category_type( 16, $id, $_POST['startdate'], $_POST['enddate'] )[0]->total;
        $Audit_Mall           = $this->get_stream_count_by_category_type( 17, $id, $_POST['startdate'], $_POST['enddate'] )[0]->total;
        $Audit_Reception_Desk = $this->get_stream_count_by_category_type( 18, $id, $_POST['startdate'], $_POST['enddate'] )[0]->total;
        $Audit_Rest_Area      = $this->get_stream_count_by_category_type( 19, $id, $_POST['startdate'], $_POST['enddate'] )[0]->total;
        $Audit_Toilets        = $this->get_stream_count_by_category_type( 20, $id, $_POST['startdate'], $_POST['enddate'] )[0]->total;

        $row = array_merge( $row, array(
            $Audit_Car_park,
            $Audit_Entrance,
            $Audit_Mall,
            $Audit_Reception_Desk,
            $Audit_Rest_Area,
            $Audit_Toilets,
            ( $Audit_Car_park + $Audit_Entrance + $Audit_Mall + $Audit_Reception_Desk + $Audit_Rest_Area + $Audit_Toilets ),
        ) );
        unset( $Audit_Car_park,
            $Audit_Entrance,
            $Audit_Mall,
            $Audit_Reception_Desk,
            $Audit_Rest_Area,
            $Audit_Toilets );

        return $row;
    }


    private function get_stores_2( $start, $end, $centreid ) {
        log_message('info', "centreid = " . $centreid . ": MEMORY: " .  memory_get_usage ( ). ": LIMIT: " .  ini_get('memory_limit') . " : " . ini_get('max_execution_time'));
        $gids       = array();


        $this->db->select( 'id' );
        $this->db->from( ' groups AS g  ' );
        $this->db->where( 'g.id > 0 ' );
        $this->db->where( '(retailer_staff = 1 OR retailer_sm = 1 OR kpi_group > 0) ' );
        $this->db->where( 'centreid', $centreid );
        $this->db->group_by( 'retailer_staff,retailer_sm,kpi_group' );
        $data = $this->db->get()->result_array();
        $this->db->flush_cache();

        if ( count( $data ) > 0 ) {
            foreach ( $data as $g ) {
                $gids[] = $g['id'];
            }
        }
        unset( $data );


        if(empty($end)) {
            $end = date("Y-m-d H:i:s", time());
        }


        $this->db->select( 'COUNT(`hd1`.`localid`) OVER () as "count"' );
        $this->db->from( ' history_devices AS hd1 ' );
        $this->db->join( sprintf( '(SELECT MAX(hd1.id) AS maxid 
FROM history_devices AS hd1 
LEFT JOIN local_groups AS lg ON (hd1.localid=lg.localid) AND hd1.roleid=lg.roleid 
LEFT JOIN local_orgs AS l ON (hd1.localid=l.id) 
WHERE hd1.id > 0 
AND l.deleted = 0 
AND hd1.centreid = %d 
AND hd1.createddate <= \'%s\' 
AND lg.groupid IN (%s)  
AND hd1.profileid > 0 
GROUP BY hd1.profileid) AS hd2 ', $centreid, date( "Y-m-d H:i:s", strtotime( $end ) ), implode( ',', $gids ) ), 'hd1.id=hd2.maxid', 'left' );

        unset($gids);
        $this->db->join('local_groups AS lg', 'hd1.localid=lg.localid AND hd1.roleid=lg.roleid', 'left');

        $this->db->where( 'hd1.id > 0' );
        $this->db->where( 'hd2.maxid IS NOT NULL' );
        $this->db->where( 'hd1.statusid != 4' );
        $this->db->where( 'hd1.profileid > 0' );
        $this->db->where( 'hd1.centreid', $centreid );
        $this->db->group_by( ' hd1.localid' );
        $this->db->limit( 1 );

        $data = $this->db->get()->row();

        return $data->count;

    }


    private function get_stores( $start, $end, $centreid ) {

        $store_gids = array();

        $this->db->select( 'id,IF(kpi_group_name="",name,kpi_group_name) AS name,retailer_staff,retailer_sm,kpi_group' );
        $this->db->from( ' groups AS g ' );
        $this->db->where( 'g.id > 0' );
        $this->db->where( '(retailer_staff = 1 OR retailer_sm = 1 OR kpi_group > 0)' );
        $this->db->where( 'centreid', $centreid );
        $this->db->group_by( ' retailer_staff,retailer_sm,kpi_group' );
        $data = $this->db->get();
        $data = $data->result_array();

        if ( count( $data ) > 0 ) {
            foreach ( $data as $g ) {
                if ( $g['retailer_sm'] == 1 ) {
                    $store_gids[] = $g['id'];
                }
                if ( $g['retailer_staff'] == 1 ) {
                    $store_gids[] = $g['id'];
                }
            }
        }


        $this->db->select( 'l.id ' );
        $this->db->from( ' local_orgs AS l ' );
        $this->db->join( 'local_groups as lg', 'l.id=lg.localid' );
        $this->db->where( 'l.id > 0' );
        $this->db->where( 'l.deleted=0' );
        $this->db->where( 'l.centreid=', $centreid );

        if ( ! empty( $store_gids ) ) {
            $this->db->where( 'lg.groupid IN (' . implode( ",", $store_gids ) . ')' );
        }

        if ( ! empty( $end ) ) {
            $this->db->where( 'l.createddate <=', date( "Y-m-d H:i:s", strtotime( $end ) ) );
        }

        $this->db->group_by( 'l.id' );
        $query = $this->db->get();

        return count( $query->result_array() );
    }

    private function get_stream_count_by_ticket_type( $typeid, $centreid, $startdate, $enddate ) {
        $this->db->select( 'count(DISTINCT t.id) as total' );
        $this->db->from( 'tickets as t' );
        $this->db->join( 'forms as f', 'f.id = t.formid', 'left' );
        $this->db->join( '(
        SELECT    MAX(id) max_id, ticketid
        FROM      ticket_history
        WHERE statusid = 2
        GROUP BY  ticketid
        )  as c_max', 'c_max.ticketid = t.id' );
        $this->db->join( 'ticket_history as h', 'h.id = c_max.max_id' );
        $this->db->join( 'category_centre_types as cct', 'f.categoryid = cct.category_id', 'left' );
        $this->db->where( 'f.deleted', 0 );
        $this->db->where( 'cct.centreid', $centreid );
        $this->db->where( 'cct.typeid', $typeid );
        $this->db->where( 't.centreid', $centreid );

        if ( ! empty( $startdate ) ) {
            $this->db->where( 't.createddate >=', date( "Y-m-d H:i:s", strtotime( $startdate ) ) );
        }
        if ( ! empty( $enddate ) ) {
            $this->db->where( 't.createddate <=', date( "Y-m-d H:i:s", strtotime( $enddate ) ) );
        }
        $query = $this->db->get();

        return $query->result();
    }

    private function get_stream_count_by_category_type( $typeid, $centreid, $startdate, $enddate ) {
        $this->db->select( 'count(DISTINCT scg.streamid) as total' );
        $this->db->from( 'streams_categories_groups as scg' );
        $this->db->join( 'category_centre_types as cct', 'scg.categoryid = cct.category_id', 'left' );
        $this->db->join( 'streams as s', 's.id = scg.streamid', 'left' );
        $this->db->where( 's.deleted', 0 );
        $this->db->where( 's.centreid', $centreid );
        $this->db->where( 'cct.centreid', $centreid );
        $this->db->where( 'cct.typeid', $typeid );
        if ( ! empty( $startdate ) ) {
            $this->db->where( 's.createddate >=', date( "Y-m-d H:i:s", strtotime( $startdate ) ) );
        }
        if ( ! empty( $enddate ) ) {
            $this->db->where( 's.createddate <=', date( "Y-m-d H:i:s", strtotime( $enddate ) ) );
        }

        $query = $this->db->get();

        return $query->result();
    }

    private function get_stream_count_by_category_type_endDate( $typeid, $centreid, $startdate, $enddate ) {
        $this->db->select( 'count(DISTINCT scg.streamid) as total' );
        $this->db->from( 'streams_categories_groups as scg' );
        $this->db->join( 'category_centre_types as cct', 'scg.categoryid = cct.category_id', 'left' );
        $this->db->join( 'streams as s', 's.id = scg.streamid', 'left' );
        $this->db->where( 's.deleted', 0 );
        $this->db->where( 's.centreid', $centreid );
        $this->db->where( 'cct.centreid', $centreid );
        $this->db->where( 'cct.typeid', $typeid );
        $this->db->where( 's.id IS NOT NULL', NULL, FALSE );
        if ( ! empty( $startdate ) ) {
            $this->db->where( 's.enddate >=', date( "Y-m-d H:i:s", strtotime( $startdate ) ) );
        }
        if ( ! empty( $enddate ) ) {
            $this->db->where( sprintf( '(s.enddate >= "%s" or s.enddate IS NULL or `s`.`enddate` = "")', date( "Y-m-d H:i:s", strtotime( $enddate ) ) ) );

        }
        $query = $this->db->get();

        return $query->result();
    }

    private function get_total_category_views_by_centre( $typeid, $centreid, $startdate, $enddate ) {
        $this->db->select( 'count(v.id) as count' );
        $this->db->from( 'views_categories as v' );
        $this->db->join( 'category_centre_types as cct', 'v.categoryid = cct.category_id', 'left' );
        $this->db->where( 'v.centreid', $centreid );
        $this->db->where( 'cct.typeid', $typeid );
        $this->db->where( 'cct.centreid', $centreid );

        if ( ! empty( $startdate ) ) {
            $this->db->where( 'v.createddate >=', date( "Y-m-d H:i:s", strtotime( $startdate ) ) );
        }
        if ( ! empty( $enddate ) ) {
            $this->db->where( 'v.createddate <=', date( "Y-m-d H:i:s", strtotime( $enddate ) ) );
        }

        $results = $this->db->get()->result_array();

        return (int) $results[0]['count'];
    }

    public function get_locals_by_activity( $centreid, $start_range = FALSE, $end_range = FALSE ) {
        $this->db->select( '`vc`.`localid`, `lo`.`name` as `local_name`, `lo`.`deleted`, COUNT(vc.localid) as count' );
        $this->db->from( 'views_categories as vc' );
        $this->db->join( 'local_orgs as lo', 'lo.id = vc.localid', 'left' );
        $this->db->where( 'vc.centreid', $centreid );
        $this->db->where( 'lo.deleted', 0 );
        $this->db->group_by( 'vc.localid' );
        $this->db->order_by( 'count ', 'DESC' );

        if ( ! empty( $start_range ) ) {
            $this->db->where( 'vc.createddate >= ', $start_range );
        }
        if ( ! empty( $end_range ) ) {
            $this->db->where( 'vc.createddate <= ', $end_range );
        }

        $query   = $this->db->get();
        $results = $query->result_array();

        return $results;
    }

    public function get_active_users_centreid( $centreid, $start_range = FALSE, $end_range = FALSE ) {

        $this->db->select( ' COUNT(DISTINCT(vc.profileid)) AS `users`' );
        $this->db->from( 'views_categories AS vc' );
        $this->db->join( 'local_orgs as l', 'vc.localid=l.id', 'left' );


        $this->db->where( 'l.deleted', 0 );
        $this->db->where( 'vc.centreid', $centreid );

        if ( ! empty( $start_range ) ) {
            $this->db->where( 'vc.createddate >=', date( "Y-m-d H:i:s", strtotime( $start_range ) ) );
        }
        if ( ! empty( $end_range ) ) {
            $this->db->where( 'vc.createddate <=', date( "Y-m-d H:i:s", strtotime( $end_range ) ) );
        }

        $this->db->group_by( 'vc.roleid' );

        $query   = $this->db->get();
        $results = $query->result_array();


        $t = 0;
        foreach ( $results as $r ) {
            $t += $r['users'];
        }


        return $t;


    }

    public function get_tickets_average_hours( $centreid, $start_range = FALSE, $end_range = FALSE ) {
        $this->db->select( 'AVG(TIMESTAMPDIFF( hour, createddate, completeddate)) AS "diff"' );
        $this->db->from( 'tickets AS t' );
        $this->db->where( 't.centreid', $centreid );
        $this->db->where( 't.deleted < ', 2 );

        if ( ! empty( $start_range ) ) {
            $this->db->where( 't.createddate >=', date( "Y-m-d H:i:s", strtotime( $start_range ) ) );
        }
        if ( ! empty( $end_range ) ) {
            $this->db->where( 't.createddate <=', date( "Y-m-d H:i:s", strtotime( $end_range ) ) );
        }
        $results = $this->db->get()->result_array();

        if ( ! empty( $results[0]['diff'] ) ) {
            return $results[0]['diff'];
        } else {
            return 0;
        }


    }
}

1 个答案:

答案 0 :(得分:0)

GROUP BY hd1.profileid) AS hd2 ', $centreid, date( "Y-m-d H:i:s", strtotime( $end ) ), implode( ',', $gids ) ), 'hd1.id=hd2.maxid', 'left' ); - 在implode之后删除一个结束括号。