我已经设置了以下代码,以为JSON列表中的每10个项目创建一个新的li项目和页面链接-但它仍显示相同的10个项目。我需要为列表创建一个简单的分页
<?php
$opts = array(
'http' => array(
'method' => "GET"
)
);
$context = stream_context_create($opts);
// Open the file using the HTTP headers set above
$json = file_get_contents('https://3rdParty.guntrader.uk/WestMidlandsShootingGround/jsonGuns?filter=SG', false, $context);
$arr = json_decode($json);
//Encode the array into a JSON string.
$encodedString = json_encode($json);
$array = json_decode($json, true);
$nb_elem_per_page = 10;
$page = isset($_GET['page']) ? intval($_GET['page'] - 1) : 0;
$data = count($array['Guns']);
$number_of_pages = intval(count($array['Guns']) / $nb_elem_per_page) + 1;
echo "
<br> <div class='container'>
<br><div class='row'>
<br>";
foreach (array_slice($array['Guns'], $page * $nb_elem_per_page, $nb_elem_per_page) as $key => $value) {
//Values in here
echo "
<br> </div>
<br> </div>
<br> ";
// that can go at the bottom
for ($i = 1; $i < $number_of_pages; $i++) {
echo "<li class='pageLink'><a href='?page=" . $i . "'>" . $i . "</a></li>";
}
}
?>
我希望每个li产品的输出显示10种不同的产品