model
public function get_customers() { $data = array(); if(is_array($this->config->get('finance_customer_group'))){ $customer_group_id = implode(",", $this->config->get('finance_customer_group')); $query = $this->db->query("SELECT *, CONCAT(firstname, ' ', lastname) AS name FROM " . DB_PREFIX . "customer WHERE customer_group_id IN (" . $customer_group_id . ") ORDER BY name ASC"); $data = $query->rows; } return $data; } I pass in Controller
$customers = $this->model_module_finance->get_customers(); $this->data['customers'] = array(); foreach($customers as $customer){ $costumer_id = $this->model_module_finance->getIdCustomer($customer['customer_id']); Передаю в model if($costumer_id['customer_id'] == $customer['customer_id']) { $this->data['customers'][] = array( 'name' => $customer['name'], 'orders' => $costumer_id['orders'], 'href' => $this->url->link('module/finance/customer_info', 'customer_id=' . $customer['customer_id'] . '&token=' . $this->session->data['token'], 'SSL') ); }else{ $this->data['customers'][] = array( 'name' => $customer['name'], 'orders' => 0, 'href' => $this->url->link('module/finance/customer_info', 'customer_id=' . $customer['customer_id'] . '&token=' . $this->session->data['token'], 'SSL') ); } } public function getIdCustomer($customer_id){ Передаю данные в Controller $query = $this->db->query("SELECT oc_order.customer_id, COUNT(oc_order.order_id) as orders FROM oc_order WHERE oc_order.customer_id = '".$customer_id."' AND oc_order.order_id NOT IN (SELECT order_id FROM oc_finance_order WHERE oc_finance_order.customer_id = '".$customer_id."' ) AND oc_order.order_status_id > 0 AND oc_order.order_status_id !=7 GROUP BY oc_order.firstname ORDER BY oc_order.firstname ASC"); return $query->row; } Long loaded, records in the database in order more than 15000 Can I speed up the download?
customeronly have those entries that haveWHERE customer_group_id IN (" . $customer_group_id . ")and repeating theorderselects those entries for which `WHERE oc_order.customer_id = '". $ customer_id. "" ` - Sender1050