0
模型中的代碼是 public function get_report6_8($ type,$ filter_id = NULL){values {array_filter}; $ filter = array($ filter_id);如何在codeigniter中動態地將值數組發送到查詢
$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();
}
在控制器中的代碼是 $數據[ '報告8'] = $這個 - > lead_report_model-> get_report6_8($型,$這 - >輸入 - >交的( '過濾器'));
代碼視圖是
如果我運行像
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發送值數組。當我從包含所有其他值的下拉菜單中選擇總計時,會發生這種情況。
感謝。它工作,但我必須在此之前添加代碼,以從數據帖子數組中捕獲數組中的鍵值。我是這樣做的。 – user2006054
public function get_report6_10($ type,$ data){ \t \t $ dropdownSelections = array(); \t \t的foreach($數據[ '過濾器']爲$鍵=> $值){ \t \t \t如果($鍵= ''!){ \t \t \t array_push($ dropdownSelections,$鍵); \t \t \t} \t \t \t} \t \t $ dropdownSelections =破滅( 「」,$ dropdownSelections); $ select =''; \t \t \t \t \t \t如果($類型== 'natbuild'){ \t \t \t \t \t $選擇= '和natbuild_principal.id在(' $ dropdownSelections。 ')'; \t \t \t \t} \t \t \t \t //回聲$選擇; – user2006054