首页 > 解决方案 > 使用 JSON 数据在 PHP 网页上进行分页

问题描述

我是 PHP 初学者。我有从 REST 服务获得的 Json 数据。我想通过各种页面将 JSON 数据分页到表格中。我在第一页上检索数据,但该页面上未显示剩余数据,这就是我想在表格上显示分页的原因。我访问了如何在 PHP 中对 JSON 数据进行分页?那个网站,但我没有完全理解。下面是我从 REST 服务获取的 json 数据。

[
{
    "bookingid": 75,
    "booking_Id": null,
    "bookingNumber": "BK201881966",
    "customerName": "",
    "customerMobileNumber": "9850944481",
    "customerId": null,
    "bookingDate": "8/19/2018 12:00:00 AM",
    "collection_time": "12:12 AM",

},
{
    "bookingid": 76,
    "booking_Id": null,
    "bookingNumber": "BK201881976",
    "customerName": "",
    "customerMobileNumber": "9850944481",
    "customerId": null,
    "bookingDate": "8/19/2018 12:00:00 AM",
    "collection_time": "07:05 PM",

},
{
    "bookingid": 77,
    "booking_Id": null,
    "bookingNumber": "BK201882077",
    "customerName": "",
    "customerMobileNumber": "",
    "customerId": null,
    "bookingDate": "8/20/2018 12:00:00 AM",
    "collection_time": "04:06 PM",

},
{
    "bookingid": 79,
    "booking_Id": null,
    "bookingNumber": "BK201882079",
    "customerName": "",
    "customerMobileNumber": "",
    "customerId": null,
    "bookingDate": "8/20/2018 12:00:00 AM",
    "collection_time": "07:10 PM",

},
{
    "bookingid": 104,
    "booking_Id": null,
    "bookingNumber": "BK2018820104",
    "customerName": "Rakesh Deshmukh",
    "customerMobileNumber": "8745938475",
    "customerId": null,
    "bookingDate": "8/20/2018 12:00:00 AM",
    "collection_time": "04:07 PM",
}
{
    "bookingid": 82,
    "booking_Id": null,
    "bookingNumber": "BK201882082",
    "customerName": "Muzzameel Sayyad",
    "customerMobileNumber": "",
    "customerId": null,
    "bookingDate": "8/20/2018 12:00:00 AM",
    "collection_time": "11:13 PM",

},
{
    "bookingid": 83,
    "booking_Id": null,
    "bookingNumber": "BK201882083",
    "customerName": "Muzzameel Sayyad",
    "customerMobileNumber": "",
    "customerId": null,
    "bookingDate": "8/20/2018 12:00:00 AM",
    "collection_time": "11:29 PM",
},
{
    "bookingid": 99,
    "booking_Id": null,
    "bookingNumber": "BK201882085",
    "customerName": "Customer One",
    "customerMobileNumber": "8347829296",
    "customerId": null,
    "bookingDate": "8/20/2018 12:00:00 AM",
    "collection_time": "12:34 PM",

},
{
    "bookingid": 103,
    "booking_Id": null,
    "bookingNumber": "BK2018820100",
    "customerName": "Customer One",
    "customerMobileNumber": "8347829296",
    "customerId": null,
    "bookingDate": "8/20/2018 12:00:00 AM",
    "collection_time": "11:10 AM",
},
{
    "bookingid": 111,
    "booking_Id": null,
    "bookingNumber": "BK2018821106",
    "customerName": "Customer One",
    "customerMobileNumber": "8347829296",
    "customerId": null,
    "bookingDate": "9/6/2018 12:00:00 AM",
    "collection_time": "09:10 PM",

}....]

我正在使用 count json 计算数据,

$total_records = count(jsonData); // I got 165 from json 
$no_of_records_per_page = 5; // I get 5 records per page
$total_pages = ceil($total_records / $no_of_records_per_page); // I got 33 from that formula

我不明白我接下来要做什么。帮助我完成我的代码。提前致谢。

标签: phphtmljson

解决方案


您需要有一个偏移量来设置您想要显示帖子的数字。在第一次加载中,您将偏移量设置为 0,在第 2 页中将偏移量设置为 5,在第 3 页中将偏移量设置为 10...

要获得更好的答案,请使用您的 PHP 代码编辑您的问题。

希望能帮助到你!


推荐阅读