是否有可能在分页条件下使用下面的查询?
$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查询而不使用分页时,我在执行“从”文本字段中执行搜索时,将得到所有正确的数据
如果我搜索20000到30000,我会在debug($data);上找到这个
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'
)
))
发布于 2016-02-16 19:57:14
因为在表单中使用的是POST方法,所以在转到下一页时可能会丢失数据。
如果仍然希望使用POST方法,则需要在会话中保存表单中的数据,并在下一页中使用这些数据。
您还可以使用GET方法(阅读更多),它将生成一个url,如:
products?min=2000&max=3000在这种情况下,不使用$this->request->data,
您需要使用$this->request->query['min']和$this->request->query['max'],并确保防止SQL注入。
但是为什么不试试这个插件:https://github.com/CakeDC/search呢?
https://stackoverflow.com/questions/35440270
复制相似问题