簡體   English   中英

cakephp:cakephp分頁條件

[英]cakephp : cakephp pagination conditions

分頁條件下使用以下查詢可使用此possibale嗎?

$data = $this->Product->query("select * from product_tbls where price >".$this->request->data["min"]." and price <".$this->request->data["max"]);

我試過這個

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

這是表格

<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查詢並且不使用分頁即時消息獲取所有正確的數據,因為我在from的文本字段中執行搜索

我在debug($data);上得到這個debug($data); 如果我搜索20000至30000

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'
    )
)

因為您在表單中使用POST方法,所以轉到下一頁時可能會丟失數據。

如果仍要使用POST方法,則需要在會話中保存表單中的數據,並在下一頁上使用它們。

您還可以使用GET方法( 更多內容 ),該方法將生成類似以下內容的網址:

products?min=2000&max=3000

在這種情況下,不要使用$this->request->data
您需要使用$this->request->query['min']$this->request->query['max'] ,並確保防止SQL注入。

但是,為什么不嘗試使用此插件: https : //github.com/CakeDC/search

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM