我正在尝试获取特定公司的客户,其中company_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,
);
}
}
同样在下面的代码中,我应该如何传递会话变量,以便客户根据公司会话变量显示?
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;
}
任何帮助都将得到很好的赞赏。谢谢
答案 0 :(得分:1)
尝试添加类似
的过滤器$this->db->select("naturescrm_customers.*");
$customer = $this->customer_m->get();
foreach ($customer as $v) {
if($adco === $v->company_id){
$elements[ $v->id] = $v->customer_id .'-'.$v->name;
}
}