0

I am using data table inbuilt ajax custom pagination.

Here i need to pass 2 parameter in limit function .

I need some help to make it possible .I am using cakephp 3.2.

Below is my code.

$sql.=" ORDER BY ". $columns[$requestData['order'][0]['column']]."   ".$requestData['order'][0]['dir']."  LIMIT ".$requestData['start']." ,".$requestData['length']."   ";


This code is in core php ,

I want to convert it into cakephp .

Below is what i have tried so far.

 $order=$requestData['order'][0]['dir'];  //descending ya ascending
        $id=$columns[$requestData['order'][0]['column']];///order by which column


 $query=  $this->Orders->find('all')->where($condition)->limit($requestData['length'])->order(['Orders.'. $id.' '.$order]);

How can i write  this code  LIMIT ".$requestData['start']." ,".$requestData['length']."   ";

Using cakephp ,
In limit how to give both the limit as well as the start parameter($requestData['start']).

Eventually ,this is the end of my problem. Thank you any suggestion will be highly appreciated.

sradha
  • 2,216
  • 1
  • 28
  • 48

2 Answers2

1

There is an offset function in cakephp query that you can use

So your query becomes as below

$query= $this->Orders->find('all')->where($condition)->offset($requestData['start'])->limit($requestData['length'])->order(['Orders.'. $id.' '.$order]);

This should work as required, it is same as start in the mysql query.

Rohit Ailani
  • 910
  • 1
  • 6
  • 19
0

In Limit, it supports two parameters if you pass only one then it is limit parameter, and offset is 0 by default

LIMIT 10 //returns first 10 records only

If you pass two parameters then first is offset and second is limit

LIMIT 50, 10 //returns 10 records from 51st record

for passing offset in CakePHP query you can use offset($start) method or page($page_number) method Check DOC

Your Code Should be

$query=  $this->Orders->find('all')->where($condition)->limit($requestData['length'])->offset($requestData['start'])->order(['Orders.'. $id.' '.$order]);
Rohit Ailani
  • 910
  • 1
  • 6
  • 19
Haresh Vidja
  • 8,340
  • 3
  • 25
  • 42