Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php CodeIgniter搜索查询过滤器参数_Php_Codeigniter_Search - Fatal编程技术网

Php CodeIgniter搜索查询过滤器参数

Php CodeIgniter搜索查询过滤器参数,php,codeigniter,search,Php,Codeigniter,Search,我正在寻找一种使用CodeIgniter和带有复选框的多个过滤器参数进行搜索的好方法。为了简单起见,想象一下: [X] T-shirts [ ] M [ ] L [X] XL [ ] Pants [ ] M [ ] L [ ] XL 一个页面显示商店中所有可用的衣服(get_all)。 您可以使用复选框仅显示t-shitrs。 像这样的东西/衣服/款式/t恤,我已经走了这么远 但是现在我想在t恤中显示L和XL尺寸(两个复选框) 我不想使用下拉菜单

我正在寻找一种使用CodeIgniter和带有复选框的多个过滤器参数进行搜索的好方法。为了简单起见,想象一下:

[X] T-shirts
    [ ] M
    [ ] L
    [X] XL
[ ] Pants
    [ ] M
    [ ] L
    [ ] XL
一个页面显示商店中所有可用的衣服(get_all)。 您可以使用复选框仅显示t-shitrs。 像这样的东西/衣服/款式/t恤,我已经走了这么远 但是现在我想在t恤中显示L和XL尺寸(两个复选框)

我不想使用下拉菜单,因为我希望能够同时显示各种组合,例如L码t恤和XL码裤子

最终,我希望这是一个基于AJAX的搜索,所以帖子比基于URI的搜索更好


实现此类功能的最佳方法是什么?

创建此表单。对每种产品类型重复此字段集(此示例显示tshirt):


请注意:这是相当不安全的。确保用户的输入有效。

创建此表单。对每种产品类型重复此字段集(此示例显示tshirt):


请注意:这是相当不安全的。确保用户的输入有效。

非常感谢!最终,我需要的不是我发布的示例,而是其他的东西,但这让我开始了!谢谢!最终,我需要的不是我发布的示例,而是其他的东西,但这让我开始了!
<form method="post" action="url/to/find_products">

    <!-- repeat for all product types -->
    <fieldset>
        <input type="checkbox" name="products[tshirt][active]" value="1" /> Tshirt

        <fieldset>
            <input type="checkbox" name="products[tshirt][size]" value="s" /> S
            <input type="checkbox" name="products[tshirt][size]" value="m" /> M
            <input type="checkbox" name="products[tshirt][size]" value="l" /> L
        </fieldset>
    </fielset>
    <!-- end repeat -->

</form>
function find_products() {
    $products = $this->input->post('products');
    $results = array();

    foreach ($products as $product => $options) {
        $table_name = $product."s";
        $query = $this->db->from($table_name);

        if (count($options['size']) > 0) {
            $query->where_in('size', $options['size']);
        }

        $results = array_merge($results, $query->get());
    }

    return $results; # Or display view, or whatever.
}