i want to display 2 array record per pages.Please help with the simple pagination.when user clicks on next page next 2 array record should display.
[dotdList] => Array
(
[0] => Array
(
[title] => Just at Rs. 799
[description] => Ambrane
)
[1] => Array
(
[title] => Flat Rs.249
[description] => Sarees & more
)
[2] => Array
(
[title] => Extra 10% off
[description] => Routers
)
[3] => Array
(
[title] => Just Rs.549
[description] => From Nova
)
)
This is what i have tried and the array contains around 1500 Records.Pagination is not looking good. Its giving very big result and if i wanna hide some of the numbers in between just to reduce its width. or may be next option or dot in between. I wanna display minimum of 15-20 records per pages.
<?phpnamespace clusterdev;class Flipkart{private $affiliateId;private $token;private $response_type;private $api_base = 'https://affiliate-api.flipkart.net/affiliate/api/';private $verify_ssl = false;function __construct($affiliateId, $token, $response_type="json")
{
$this->affiliateId = $affiliateId;
$this->token = $token;
$this->response_type = $response_type;
$this->api_base.= $this->affiliateId.'.'.$this->response_type;
}
public function api_home(){
return $this->sendRequest($this->api_base);
}
public function call_url($url){
return $this->sendRequest($url);
}
private function sendRequest($url, $timeout=30){
if (function_exists('curl_init') && function_exists('curl_setopt')){
$headers = array(
'Cache-Control: no-cache',
'Fk-Affiliate-Id: '.$this->affiliateId,
'Fk-Affiliate-Token: '.$this->token
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_USERAGENT, 'PHP-ClusterDev-Flipkart/0.1');
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->verify_ssl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result = curl_exec($ch);
curl_close($ch);
return $result ? $result : false;
}else{
return false;
} }}$flipkart = new \clusterdev\Flipkart("shopXXonh", "4e88c0b31f3b45XXXa746fcfdae39af", "json");$alloffers_url ='https://affiliate-api.flipkart.net/affiliate/offers/v1/all/json';$url = isset($_GET['url'])?$_GET['url']:false;if($url){$hidden = isset($_GET['hidden'])?false:true;$details = $flipkart->call_url($url);if(!$details){echo 'Error: Could not retrieve products list.';exit();
}
$details = json_decode($details, TRUE);}$offer = isset($_GET['offer'])?$_GET['offer']:false;if($offer){if($offer == 'alloffers'){
$details = $flipkart->call_url($alloffers_url);if(!$details)
{
echo 'Error: Could not retrieve Top Offers.';
exit();
}
$details = json_decode($details, TRUE);
$list = $details['allOffersList'];
echo '<h2> All Offers</h2>';
echo "<table cellpadding=10 cellspacing=1 style='text-align:center'>";
$count = 0;
$end = 1;if(count($list) > 0){
//foreach ($list as $item)
//{
$count++;
/*echo"<pre/>";
print_r($list);
echo"<pre/>";*/
$page = isset($_REQUEST['page']) && $_REQUEST['page'] > 0 ? $_REQUEST['page'] : 1;
function display($list, $page = 1)
{
$start = ($page - 1) * 2;
$item = array_slice($list, $start, 2);
foreach ($list as $key => $val) {
/*echo"<pre/>";
print_r($list);
echo"<pre/>";*/
echo $val['title'] . '<br/>';
echo $val['description'] . '<br/>';
echo "<br>";}}$len = count($list);echo $len."<br/>";$pages = ceil($len /2);echo $pages;if ($page > $pages or $page < 1) {echo 'page not found';}else{display($list, $page);
for ($i = 1 ; $i <= $pages ; $i++)
{
$current = ($i == $page) ? TRUE : FALSE;
if ($current) {
echo '<b>' . $i . '</b>';
}else
{?><a href="http://localhost/flipkart-api/fkt_offer.php?offer=alloffers&page=<?php echo $i;?>"><?php echo $i;?></a><?php }}}}if($count==0){echo'<tr><td>No Top Offers returned.</td><tr>';}exit();}else{
echo 'Error: Invalid offer type.';
exit();}}echo '<h2> <a href="?offer=alloffers">All Offers</a></h2><br><br>';?>