Search code examples
phpjqueryajaxcodeignitercodeigniter-3

How to get one variable for Multiple Value in method GET php CodeIgniter


URL Created http://localhost/ci_search/product_filter/1?brand=Honor&brand=Infinix&brand=VIVO

URL I want

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;
    }
});

Solution

  • At First I used implode to split array using post request

    $brand=$this->input->post('brand');
    $brands=implode(",",$brand);
    

    then i redirected to a url for get request

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