是的你可以。您必须遵守此处的分页规则。您需要在 url 中传递页码和记录限制。
www.example.com/index.php?page=1&limit=10
现在,您创建一个文本或 php 文件,并使用 var_export 导出其中的所有数据以返回数组或您喜欢的其他方式。
现在你必须获取页码,技巧就在这里。
从文本文件中获得的数组应按限制划分。
$rows = array_chunk($array,$_GET['limit'])
;
您的第 = $n 页的结果就在这里。$result = $row[$_GET['page']]
这是我的index.php 文件。
<?php
$array = include_once('data.php');
$page = $_GET['page'] ? $_GET['page'] : 0;
$limit = $_GET['limit'];
$rows = array_chunk($array,$limit);
$result = $rows[$page];
?>
<table>
<tr>
<th>Id</th>
<th>Name</th>
<th>Desc</th>
<th>Status</th>
</tr>
<?php
foreach ($result as $res) {
?>
<tr>
<td><?php echo $res['id'] ?></td>
<td><?php echo $res['name'] ?></td>
<td><?php echo $res['desc'] ?></td>
<td><?php echo $res['status'] ?></td>
</tr>
<?php
}
?>
<tr>
<td colspan="2">
<?php
if($page>0)
{
?>
<a href="index.php?limit=<?php echo $limit; ?>&page=<?php echo ($page-1); ?>">Previous</a>
<?php
}
?>
</td>
<td colspan="2">
<?php
if (isset($rows[$page+1]))
{
?>
<a href="index.php?limit=<?php echo $limit; ?>&page=<?php echo ($page+1); ?>">Next</a>
<?php
}
?>
</td>
</tr>
</table>
这是 data.php 文件。我已经使用数组来返回值。
<?php
return
$array = [
[
'id' => 1,
'name' => 'A',
'desc' => 'Test',
'status' => 'Active'
],
[
'id' => 2,
'name' => 'B',
'desc' => 'Test',
'status' => 'Active'
],
[
'id' => 3,
'name' => 'C',
'desc' => 'Test',
'status' => 'Active'
],
[
'id' => 4,
'name' => 'D',
'desc' => 'Test',
'status' => 'Active'
],
[
'id' => 5,
'name' => 'E',
'desc' => 'Test',
'status' => 'Active'
],
[
'id' => 6,
'name' => 'F',
'desc' => 'Test',
'status' => 'Active'
],
];