Php 如何在codeigniter中显示应用于电子商务站点产品的过滤器数量?
我已经在我的站点中为产品添加了一些过滤器(如价格、品牌、类别等),现在我想显示应用了多少个过滤器 这是查看页面:Php 如何在codeigniter中显示应用于电子商务站点产品的过滤器数量?,php,mysql,codeigniter,Php,Mysql,Codeigniter,我已经在我的站点中为产品添加了一些过滤器(如价格、品牌、类别等),现在我想显示应用了多少个过滤器 这是查看页面: <div class="btn btn-info" data-toggle="modal" data-target="#myModal" style="width:130px;"> <div class="list-updtr__img"></div> <div class="list-updtr__lbl" style="fo
<div class="btn btn-info" data-toggle="modal" data-target="#myModal" style="width:130px;">
<div class="list-updtr__img"></div>
<div class="list-updtr__lbl" style="font-size:12px;">FILTER BY</div>
<div class="list-updtr__val" style="font-size: 10px;margin-left: 18px;">0 filters applied</div>
</div>
在上面的代码中,我在哪里添加过滤器计数,我需要设置计数需要增加的标志,当应用过滤器时,首先,在实际控制器开始像这样工作之前,您需要声明会话变量
$_SESSION['filters_counter'] = 0;
现在,每当任何用户应用任何过滤器时,只要像这样增加控制器中的filter\u计数器
变量
if ($this->input->get_post('deal_type')) {
$this->data['current_deal_type'] = explode('-', $this->input->get_post('deal_type'));
$filters['deals.deal_type'] = $this->data['current_deal_type'];
$_SESSION['filters_counter'] += 1;
}
if ($this->input->get_post('tags')) {
$this->data['current_tags'] = explode('-', $this->input->get_post('tags'));
$filters['deals.tags'] = $this->data['current_tags'];
$_SESSION['filters_counter'] += 1;
}
if ($this->input->get_post('s')) {
$filters['deals.deal_title'] = $this->input->get_post('s');
$_SESSION['filters_counter'] += 1;
}
if ($this->input->get_post('min_price')) {
$filters['deals.deal_price >='] = $this->input->get_post('min_price');
$_SESSION['filters_counter'] += 1;
}
if ($this->input->get_post('max_price')) {
$filters['deals.deal_price <='] = $this->input->get_post('max_price');
$_SESSION['filters_counter'] += 1;
}
/* External filters ends here */
/* sort filters starts here */
$sort_filters = array('deals.position_number' => 'ASC');
if ($this->input->get_post('sort')) {
if ($this->input->get_post('sort') == 'popularity-desc') {
//Need add script after implementing views count for each deal
} elseif ($this->input->get_post('sort') == 'price-asc') {
$sort_filters = array('deals.deal_price' => 'ASC');
} elseif ($this->input->get_post('sort') == 'price-desc') {
$sort_filters = array('deals.deal_price' => 'DESC');
} elseif ($this->input->get_post('sort') == 'newest-desc') {
$sort_filters = array('deals.created_date_time' => 'DESC');
}
$_SESSION['filters_counter'] += 1;
}
<div class="btn btn-info" data-toggle="modal" data-target="#myModal" style="width:130px;">
<div class="list-updtr__img"></div>
<div class="list-updtr__lbl" style="font-size:12px;">FILTER BY</div>
<div class="list-updtr__val" style="font-size: 10px;margin-left: 18px;">$_SESSION['filters_counter'] filters applied</div>
</div>
if($this->input->get\u post('deal\u type')){
$this->data['current\u deal\u type']=分解('-',$this->input->get\u post('deal\u type');
$filters['deals.deal\u type']=$this->data['current\u deal\u type'];
$\会话['filters\u counter']+=1;
}
如果($this->input->get_post('tags')){
$this->data['current_tags']=分解('-',$this->input->get_post('tags');
$filters['deals.tags']=$this->data['current_tags'];
$\会话['filters\u counter']+=1;
}
如果($this->input->get_post('s')){
$filters['deals.deal_title']=$this->input->get_post('s');
$\会话['filters\u counter']+=1;
}
如果($this->input->get\u post('min\u price')){
$filters['deals.deal_price>=']=$this->input->get_post('min_price');
$\会话['filters\u counter']+=1;
}
如果($this->input->get\u post('max\u price')){
$filters['deals.deal\u price您可以在会话中存储筛选器计数。@Ropalimunsi我不知道如何计数筛选器的数目每当您在代码中应用任何筛选器时,只需增加会话值。@Ropalimunsi请查看上述代码,您能告诉我在哪里添加筛选器吗session@Prajakta很高兴知道它帮助了你,如果你不介意的话,你可以爬起来投票决定答案。
if ($this->input->get_post('deal_type')) {
$this->data['current_deal_type'] = explode('-', $this->input->get_post('deal_type'));
$filters['deals.deal_type'] = $this->data['current_deal_type'];
$_SESSION['filters_counter'] += 1;
}
if ($this->input->get_post('tags')) {
$this->data['current_tags'] = explode('-', $this->input->get_post('tags'));
$filters['deals.tags'] = $this->data['current_tags'];
$_SESSION['filters_counter'] += 1;
}
if ($this->input->get_post('s')) {
$filters['deals.deal_title'] = $this->input->get_post('s');
$_SESSION['filters_counter'] += 1;
}
if ($this->input->get_post('min_price')) {
$filters['deals.deal_price >='] = $this->input->get_post('min_price');
$_SESSION['filters_counter'] += 1;
}
if ($this->input->get_post('max_price')) {
$filters['deals.deal_price <='] = $this->input->get_post('max_price');
$_SESSION['filters_counter'] += 1;
}
/* External filters ends here */
/* sort filters starts here */
$sort_filters = array('deals.position_number' => 'ASC');
if ($this->input->get_post('sort')) {
if ($this->input->get_post('sort') == 'popularity-desc') {
//Need add script after implementing views count for each deal
} elseif ($this->input->get_post('sort') == 'price-asc') {
$sort_filters = array('deals.deal_price' => 'ASC');
} elseif ($this->input->get_post('sort') == 'price-desc') {
$sort_filters = array('deals.deal_price' => 'DESC');
} elseif ($this->input->get_post('sort') == 'newest-desc') {
$sort_filters = array('deals.created_date_time' => 'DESC');
}
$_SESSION['filters_counter'] += 1;
}
<div class="btn btn-info" data-toggle="modal" data-target="#myModal" style="width:130px;">
<div class="list-updtr__img"></div>
<div class="list-updtr__lbl" style="font-size:12px;">FILTER BY</div>
<div class="list-updtr__val" style="font-size: 10px;margin-left: 18px;">$_SESSION['filters_counter'] filters applied</div>
</div>