【问题标题】:Pagination on PHP webpage using JSON data [duplicate]使用JSON数据在PHP网页上分页[重复]
【发布时间】:2018-10-15 12:01:21
【问题描述】:

我是 PHP 初学者。我有从 REST 服务获得的 Json 数据。我想通过各种页面将 JSON 数据分页到表格中。我在第一页上检索数据,但该页面上未显示剩余数据,这就是我想在表格上显示分页的原因。我访问了How to do Pagination for JSON data in PHP? 该站点,但我并没有完全理解。以下是我从 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

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

【问题讨论】:

  • 欢迎来到 StackOverflow。您已经链接到一个工作示例,您对分页有什么不了解的地方?

标签: php html json


【解决方案1】:

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

如需更好的答案,请使用您的 PHP 代码编辑您的问题。

希望对你有帮助!

【讨论】:

  • "在第 3 页中,您将偏移量设置为 3" 您的意思是 10?
  • 是的,很抱歉,但你必须以动态方式进行。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-07-19
  • 1970-01-01
  • 2014-05-21
  • 1970-01-01
  • 2016-12-27
相关资源
最近更新 更多