#create a array pagination class page.
<?php
class pagination
{
var $page = 1; // Current Page
var $perPage = 10; // Items on each page, defaulted to 10
var $showFirstAndLast = false; // if you would like the first and last page options.
function generate($array, $perPage = 10)
{
// Assign the items per page variable
if (!empty($perPage))
$this->perPage = $perPage;
// Assign the page variable
if (!empty($_GET['page'])) {
$this->page = $_GET['page']; // using the get method
} else {
$this->page = 1; // if we don't have a page number then assume we are on the first page
}
// Take the length of the array
$this->length = count($array);
// Get the number of pages
$this->pages = ceil($this->length / $this->perPage);
// Calculate the starting point
$this->start = ceil(($this->page - 1) * $this->perPage);
// Return the part of the array we have requested
return array_slice($array, $this->start, $this->perPage);
}
function links()
{
// Initiate the links array
$plinks = array();
$links = array();
$slinks = array();
// Concatenate the get variables to add to the page numbering string
if (count($_GET)) {
$queryURL = '';
foreach ($_GET as $key => $value) {
if ($key != 'page') {
$queryURL .= '&'.$key.'='.$value;
}
}
}
// If we have more then one pages
if (($this->pages) > 1)
{
// Assign the 'previous page' link into the array if we are not on the first page
if ($this->page != 1) {
if ($this->showFirstAndLast) {
$plinks[] = ' <a href="?page=1'.$queryURL.'">«« First </a> ';
}
$plinks[] = ' <span class="paginationPrev"><a href="?page='.($this->page - 1).$queryURL.'">« Prev</a></span> ';
}
// Assign all the page numbers & links to the array
echo '<span nowrap="nowrap" align="center">';
for ($j = 1; $j < ($this->pages + 1); $j++) {
if ($this->page == $j) {
$links[] = ' <span class="selected1">'.$j.'</span> '; // If we are on the same page as the current item
} else {
$links[] = ' <a href="?page='.$j.$queryURL.'">'.$j.'</a>'; // add the link to the array
}
}
echo '</span>';
echo '<span class="paginationNext">';
// Assign the 'next page' if we are not on the last page
if ($this->page < $this->pages) {
$slinks[] = ' <a href="?page='.($this->page + 1).$queryURL.'"> Next » </a> ';
if ($this->showFirstAndLast) {
$slinks[] = ' <a href="?page='.($this->pages).$queryURL.'"> Last »» </a> ';
}
}
echo '</span>';
// Push the array into a string using any some glue
return implode(' ', $plinks).implode($this->implodeBy, $links).implode(' ', $slinks);
}
return;
}
}
?>
-------------------------------End pagination class-----------------------------------------
#include pagination class
#shopping.com api implement using php(shopapi.php) ;
<div class="proright">
<?php
include('php_array_pagingnation.php');
$requey=$_REQUEST['categoryname'];
$response = new SimpleXMLElement(
"http://sandbox.api.shopping.com/publisher/3.0/rest/GeneralSearch?apiKey=authorized-key&trackingId=7000610&keyword=$requey&numItems=1000",
null,
true
);
echo "<pre>";print_r($response);
?>
<div class="main_cart">
<?php
echo "<span style=\"padding-left:5px;\"><h2>$requey</h2></span>";
//print_r($response);
$pagination = new pagination;
foreach ($response->categories->category->items->product as $value) {
$products[] = array(
'Productname' => $value->name,
'productOffersURL' => $value->productOffersURL,
'sourceURL' => $value->images->image->sourceURL,
'storeNotes' => $value->numStores,
'Price' => $value->minPrice,
'reviewURL' => $value->rating->reviewURL,
'reviewCount' => $value->rating->reviewCount,
'ratingImage' => $value->rating->ratingImage->sourceURL,
);
}
// If we have an array with items
if (count($products)) {
// Parse through the pagination class
$productPages = $pagination->generate($products, 40);
// If we have items
if (count($productPages) != 0) {
// Create the page numbers
echo $pageNumbers = '<div class="paginationNew"><div class="numbers">'.$pagination->links().'</div></div>';
// Loop through all the items in the array
foreach ($productPages as $productArray) {?>
<div class="cart_det">
<a href="<?php echo $productArray['productOffersURL']; ?>" target="_blank"><img src="<?php echo $productArray['sourceURL']; ?>" width="152" height="150"/></a>
<div class="name"> <a href="<?php echo $productArray['productOffersURL']; ?>" target="_blank"><?php echo $productArray['Productname']; ?></a></div>
<ul class="rate_det">
<li class="price">From $<?php echo $productArray['Price']; ?></li>
<li class="shiping">Free Shipping</li>
<li class="story" ><?php echo $productArray['storeNotes']; ?> stores</li>
<li class="reviewno" >
<?php if(!empty($productArray['reviewURL'])){?>
<a href="<?php echo $productArray['reviewURL']; ?>" target="_blank">Reviews (<?php echo $productArray['reviewCount']; ?>) </a>
<?php }else{?>
<?php }?>
</li>
<li class="ratingimg">
<?php if(!empty($productArray['ratingImage'])){?>
<img src="<?php echo $productArray['ratingImage']; ?>" border="0" width="91">
<?php }else{?>
<img src="images/sdc_stars_sm_blnk.gif" border="0" width="91">
<?php }?>
</li>
</ul>
</div>
<?php }
// print out the page numbers beneath the results
}
}
?>
</div>
<?php echo $pageNumbers = '<div class="numbers">'.$pagination->links().'</div>';?>
</div>