Last active
November 7, 2016 12:24
-
-
Save iamswapnilsonar/d3dd84b169afb631c07a1355eb58d0c8 to your computer and use it in GitHub Desktop.
Revisions
-
iamswapnilsonar revised this gist
Nov 7, 2016 . No changes.There are no files selected for viewing
-
iamswapnilsonar created this gist
Nov 7, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ <?php //Swapnil_Sonar workspace $sample_data = '[{"id":1,"name":"Item1","type":"Android"},{"id":2,"name":"Item2","type":"Android"},{"id":3,"name":"Item3","type":"iOS"},{"id":4,"name":"Item4","type":"Windows"},{"id":5,"name":"Item5","type":"iOS"},{"id":6,"name":"Item6","type":"Android"},{"id":7,"name":"Item7","type":"Windows"}]'; // just normal getting data $raw_data = json_decode($sample_data, true); // use get variable to paging number $page = 2; //!isset($_GET['page']) ? 1 : $_GET['page']; $limit = 5; // five rows per page $offset = ($page - 1) * $limit; // offset $total_items = count($raw_data); // total items $total_pages = ceil($total_items / $limit); $final = array_splice($raw_data, $offset, $limit); // splice them according to offset and limit echo json_encode($final); ?>