Skip to content
Advertisement

Create a NEXT and PREVIOUS to display records of JSON data

I have created a JSON file with the following fields:
Name| Age| Gender
There are total 50 records. Here I require 2 functionalities.

  1. Display 10 records per page and
  2. Cycle through records using NEXT and PREV buttons only.

I tried searching but everyone has tried with mysql and javascript which I have tried and got so many errors. So, can anyone help me with this.

This is the php code I’ve used:

JavaScript

Here I have encountered the following errors:

  1. All the records are displayed in the page and even it is repeating in the next page.
  2. Here I wanted to insert the Next and previous buttons instead of the page numbers.

This is the result I have got till now: sample

Advertisement

Answer

Here’s something you can build on. Of course you can’t just copy and paste – that makes it harder to be sure that the required understanding has sunk-in! I’ve written it quick-n-dirty. You can extract the required logic AND add some error checking…

data.json

JavaScript

showResults.php

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement