首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >cakephp : cakephp分页条件

cakephp : cakephp分页条件
EN

Stack Overflow用户
提问于 2016-02-16 18:25:07
回答 1查看 176关注 0票数 1

是否有可能在分页条件下使用下面的查询?

代码语言:javascript
复制
$data = $this->Product->query("select * from product_tbls where price >".$this->request->data["min"]." and price <".$this->request->data["max"]);

我试过这个

代码语言:javascript
复制
$data = $this->Product->find('all');
    if(isset($this->request->data["min"]))
    {
        $this->paginate = array(
                            'conditions' => array('Product.price >' => $this->request->data["min"] ,'Product.price <'=>$this->request->data["max"]),
                            'limit' => 6,
                            'order' => array('id' => 'desc')
                            );
        $data = $this->paginate('Product');
    }

这是表格

代码语言:javascript
复制
<form method="post">
    <table>
        <tr>
            <td><h5><b>Enter Price</b></h5></td>
            <td><input type="text" name="min" placeholder="Min" size="4"></td>
            <td><h5>To</h5></td>
            <td><input type="text" name="max" placeholder="Max" size="4"></td>
        </tr>
        <tr>
            <td><input type="submit" name="b1" value="Search"></td>
        </tr>
    </table>
</form>

所有我都在使用这段代码。当使用普通php查询而不使用分页时,我在执行“从”文本字段中执行搜索时,将得到所有正确的数据

如果我搜索20000到30000,我会在debug($data);上找到这个

代码语言:javascript
复制
array(
(int) 0 => array(
    'Product' => array(
        'id' => '43',
        'category_tbls_id' => '3',
        'subcategory_tbls_id' => '22',
        'brands_tbls_id' => '0',
        'product_description' => 'product desc',
        'name' => 'Utsav Fashion Pink Net Saree',
        'price' => '22000',
        'photo' => '145500138232.jpg'
    ),
    'brands_tbls' => array(
        'id' => '0',
        'name' => 'no brand'
    )
),
(int) 1 => array(
    'Product' => array(
        'id' => '26',
        'category_tbls_id' => '2',
        'subcategory_tbls_id' => '11',
        'brands_tbls_id' => '4',
        'product_description' => 'Product description here.',
        'name' => 'Spykar Jeans',
        'price' => '2400',
        'photo' => '14544135633.jpg'
    ),
    'brands_tbls' => array(
        'id' => '4',
        'name' => 'spykar'
    )
)

)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-02-16 19:57:14

因为在表单中使用的是POST方法,所以在转到下一页时可能会丢失数据。

如果仍然希望使用POST方法,则需要在会话中保存表单中的数据,并在下一页中使用这些数据。

您还可以使用GET方法(阅读更多),它将生成一个url,如:

代码语言:javascript
复制
products?min=2000&max=3000

在这种情况下,不使用$this->request->data

您需要使用$this->request->query['min']$this->request->query['max'],并确保防止SQL注入。

但是为什么不试试这个插件:https://github.com/CakeDC/search呢?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35440270

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档