Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.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 如何将有限的数据分页_Php - Fatal编程技术网

Php 如何将有限的数据分页

Php 如何将有限的数据分页,php,Php,我正在使用Laravel4.2进行规划。我试图从第一页50的数据中获取数据,然后第二页将获得另一个新的50数据 我确实尝试了该代码,但它仍然从数据库获取所有数据。请尝试以下操作: $rowsPerPage = 50; $num = 1; $offsets = ($num - 1) * $rowsPerPage; $data['trans'] = Transaction::withoutBranch() ->select('id', 'amount'

我正在使用Laravel4.2进行规划。我试图从第一页50的数据中获取数据,然后第二页将获得另一个新的50数据

我确实尝试了该代码,但它仍然从数据库获取所有数据。

请尝试以下操作:

    $rowsPerPage = 50;
    $num = 1;
    $offsets = ($num - 1) * $rowsPerPage;

    $data['trans'] = Transaction::withoutBranch()
    ->select('id', 'amount')
    ->where('payment_date', '>=', '2019-06-07')
    ->limit($offsets)
    ->get();
可能重复的
$data['trans'] = Transaction::withoutBranch()
    ->select('id', 'amount')
    ->where('payment_date', '>=', '2019-06-07')
    ->limit($rowsPerPage)
    ->offset($offsets)
    ->get();