Created
January 25, 2016 20:06
-
-
Save TravisBallard/aa41ed40fa8023e81702 to your computer and use it in GitHub Desktop.
This file contains 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 characters
<?php | |
$total = 3270; | |
$perPage = 20; | |
$curPage = isset( $_REQUEST['page'] ) && ! empty( $_REQUEST['page'] ) ? intval( $_REQUEST['page'] ) : 1; | |
// set start position | |
$start = (($curPage * $perPage) - $perPage) + 1; | |
if( $start === 0 ) $start = 1; | |
// set end position | |
$end = ($start + $perPage) - 1; | |
if( $end > $total ) $end = $total; | |
// get total pages | |
$max = ceil( $total / $perPage ); | |
// if current page is last, set start to last of previous page | |
if( $curPage == $max ){ | |
$start = ($max - 1) * $perPage; | |
} | |
// more than max, nothing to show | |
if( $start > $end ){ | |
die(); | |
} | |
$arr = array( | |
'meta' => array( | |
"total_resources" => $total, | |
"resources_per_page" => $perPage, | |
"current_page" => $curPage | |
), | |
'result' => array() | |
); | |
for( $x=$start; $x<=$end; $x++){ | |
$tmp = (object)array( | |
'title' => sprintf( 'Item %d', $x ), | |
'file_url' => null, | |
'node_created' => 'Thursday, September 24, 2015 - 00:00', | |
'nid' => $x, | |
'type' => 'Test', | |
'image' => null, | |
'related_industry' => null | |
); | |
array_push( $arr['result'], $tmp ); | |
} | |
die(json_encode((object)$arr)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment