1
我想獲取特定公司的客戶,其中company_id
是會話變量。我將發佈我的控制器的代碼在數據被提取的地方。目前,所有的客戶都被抓取,而不是特定公司的客戶。Codeigniter:基於特定公司ID獲取客戶
CODE:
public function index()
{
if($this->input->post("export_btn")){
$type = $this->input->post("type");
$sel_elements = $this->input->post("selectItemsel_elements");
// filename for download
if("customer" == $type){
$adco = $this->session->userdata('company_id');
$this->db->select("naturescrm_customers.* FROM naturescrm_customers");
$this->db->join("naturescrm_company","naturescrm_company.company_id=naturescrm_customers.company_id AND naturescrm_customers.company_id='".$adco."'","left");
$customers = $this->customer_m->get_by("id IN (".implode(",",$sel_elements).")");
foreach($customers as $order){
$data[] = array(
"customer_id" =>"".$order->customer_id,
"first name" =>$order->name,
"last name" =>$order->lname,
"address 1" =>$order->address,
"address 2" =>$order->add2,
"city" =>$order->city,
"state" =>$order->state,
"country" =>$order->country,
"zip_code" =>$order->zip_code,
"email" =>$order->email,
"phone" =>$order->phone,
);
}
}
同樣在下面的代碼,我怎麼讓客戶出現基於該公司session變量來傳遞會話變量?
CODE
if("customer" == $type){
$elements = array();
$adco = $this->session->userdata('company_id');
$customer = $this->customer_m->get();
foreach ($customer as $v) {
$elements[ $v->id] = $v->customer_id .'-'.$v->name;
}
$this->data['elements'] = $elements;
}
任何幫助將gratly讚賞。謝謝
附加where條件加入後'$這個 - > DB->其中( 「naturescrm_company.company_id」,$ ADCO)' –
好吧,我會嘗試你的代碼。在這種情況下,我是否刪除了連接中的AND? –
如果你目前獲取所有記錄然後,不只是嘗試只添加條件:) –