0

模型中的代码是 public function get_report6_8($type, $filter_id=NULL) { $values = array($filter_id);

$select = '';       
if ($filter_id && $type == 'jh') {
    $select = 'and natbuild_rep.jh_rep_id = ?';
}
else if ($filter_id && $type == 'natbuild') {
    $select = 'and natbuild_principal.id = ?';
}

$sql = "select sum(total) total
    from (
        select value_of_sale total
        from lead
        left join natbuild_rep
        on natbuild_rep.mobile = lead.mobile
        left join natbuild_store
        on natbuild_store.id = natbuild_rep.store_id
        left join natbuild_principal
        on natbuild_principal.store_group = ifnull(natbuild_store.store_group2, natbuild_store.store_group)
        where (status = 1 OR status = 2)
        and value_of_sale is not null
        {$select}
        group by lead.id
    ) temp";

return $this->db->query($sql, $values)->row();
}

控制器中的代码是 $data['report8'] = $this->lead_report_model->get_report6_8($type, $this->input->post('filter'));

视图中的代码是

  • 总计:$total)) ? $report8->总计:0;?>
  • 如果我像这样运行查询

    select sum(total) total
    
    from (
    
        select value_of_sale total
        from lead
        left join natbuild_rep
        on natbuild_rep.mobile = lead.mobile
        left join natbuild_store
        on natbuild_store.id = natbuild_rep.store_id
        left join natbuild_principal
        on natbuild_principal.store_group = ifnull(natbuild_store.store_group2, natbuild_store.store_group)
    where (status = 1 OR status = 2)
        and value_of_sale is not null
        and natbuild_principal.id in (18, 30, 31, 35, 33, 25, 23, 15, 8, 6, 5, 29, 7, 3, 2, 1, 24, 27, 22, 21, 20, 26, 36)
    group by lead.id ) temp
    

    结果是对的。请帮助我如何将值数组发送到 $select。当我从包含所有其他值的下拉列表中选择总计时,就会发生这种情况。

    4

    1 回答 1

    0

    您的下拉菜单是多选的,因此它将传递一个包含值的数组。

    利用

     implode(",", $dropdownSelections);
    
     $select = 'and natbuild_principal.id in ('.implode(",", $dropdownSelections).')';
    
    于 2013-01-24T03:19:12.673 回答