【问题标题】:How to get one variable for Multiple Value in method GET php CodeIgniter如何在方法 GET php CodeIgniter 中为多值获取一个变量
【发布时间】:2020-09-06 08:55:14
【问题描述】:

已创建网址 http://localhost/ci_search/product_filter/1?brand=Honor&brand=Infinix&brand=VIVO

我想要的网址

http://localhost/ci_search/product_filter/1?brand=Honor,Infinix,VIVO

<form id="form" method="GET" action="<?= base_url('product_filter/filter_url') ?>">
<div class="container">
    <div class="row">
foreach($brand_data->result_array() as $key=>$row)
                {
                ?>
                <div class="list-group-item checkbox">
                    <label><input  type="checkbox" name="brand[]" class="common_selector brand" value="<?php echo $row['product_brand']; ?>" > <?php echo $row['product_brand']; ?></label>
                </div>
                <?php
                }
                ?>
</div>

JQUERY

$(document).ready(function(){

$(".brand").change(function() {
if(this.checked) {
    //Do stuff

    alert(get_filter('brand'));
    $("#form").submit();
}

});

function get_filter(class_name)
    {
        var filter = [];
        $('.'+class_name+':checked').each(function(){
            filter.push($(this).val());
        });
        return filter;
    }
});

【问题讨论】:

    标签: php jquery ajax codeigniter codeigniter-3


    【解决方案1】:

    起初我使用implode 使用post request

    来拆分数组
    $brand=$this->input->post('brand');
    $brands=implode(",",$brand);
    

    然后我重定向到获取请求的 url

    redirect(base_url('product/category/detail?').'brand='.$brands);
    

    【讨论】:

      猜你喜欢
      • 2020-08-05
      • 1970-01-01
      • 2012-04-14
      • 1970-01-01
      • 1970-01-01
      • 2015-03-20
      • 1970-01-01
      • 2012-04-05
      • 2012-09-29
      相关资源
      最近更新 更多