title: How to do Pagination for JSON data in PHP?
body: <p>I don't have direct access to database from PHP. if it was so, I could have done pagination simply. Here I send a GET request to a PHP web service, and the result from the database is fetched as JSON. And I have a table and I want to show the database values into it. Since database table contains more than 1000 records, I want to show the data paginated.</p>
  
  <pre><code>$json_data_fromdb= httpGet($ur3l."fromtable?u=".$var1."&amp;ip=".$var2);
  $array = json_decode($json_data_fromdb, true);
  $x=count($array['qqq']);
  $array = $array['qqq'];
  </code></pre>
  
  <p>The above given is the GET request and the corresponding JSON is stored in $array.</p>
  
  <p>How can I do pagination to a JSON array  using PHP??</p>
  
  <p>My JSON data is like this:</p>
  
  <pre><code>{
      "qqq": [
          {
              "a": "Conne",
              "b": "1",
              "c": "2014-05-19T15:40:06+05:30",
              "d": {
                  "d1": "dani",
  
                  "d6": "admin"
              }
  
          },
          {
              "a": "igroup'",
              "b": "1235",
              "c": "2014-05-27T11:23:11+05:30",
              "d": {
                  "d1": "sev",
  
                  "d6": "eev"
              }
  
          }
      ]
  }
  </code></pre>
  
  <p>And below given is my HTML table</p>
  
  <pre><code> &lt;table id="show" &gt;
          &lt;thead &gt;
          &lt;tr &gt;
              &lt;th&gt;1stheader&lt;/th&gt;
              &lt;th&gt;2stheader&lt;/th&gt;
              &lt;th&gt;3stheader&lt;/th&gt;
              &lt;th&gt;4stheader&lt;/th&gt;
              &lt;th&gt;5stheader&lt;/th&gt;
          &lt;/tr&gt;
          &lt;/thead&gt;
          &lt;tbody&gt;
          &lt;?php
          for($i=0; $i&lt;$x; $i++)
          {
              $a= $array[$i]['a'];
              $b= $array[$i]['d']['d1'] ;
              $c= $array[$i]['d']['d2'] ;
              $d= $array[$i]['b'];
              $e= $array[$i]['c'];
  
              ?&gt;
              &lt;tr &gt;
                  &lt;td&gt;&lt;?php echo $a; ?&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;?php echo $b  ?&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;?php echo c;   ?&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;?php echo d;   ?&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;?php echo $e;  ?&gt;&lt;/td&gt;
              &lt;/tr&gt;
          &lt;?php }  ?&gt;
          &lt;/tbody&gt;
      &lt;/table&gt;
  </code></pre>