///////////////FILLING ARRAY WITH DUMMY DATA////////////////////
$key = array();
for($i=0; $i<200; $i++)
{
//fill array data
$key[] = "num = ".$i;
}
////////////////////////////////////////////////////////////////
/////////////////////START OF ARRAY PAGINATION CODE/////////////////////
$ptemp="http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
$pt=explode('&',$ptemp);
if (strpos($ptemp,'pageno'))
array_pop($pt);
$pt=implode('&',$pt);
$ptemp=$pt;
$array=$key; // REPLACE $KEY WITH YOUR ARRAY VARIABLE
$page = $_REQUEST['pageno'];
$currentpage = isset($page) ? (integer)$page : 1;
$numperpage = 10; //NUMBER OF RECORDS TO BE DISPLAYED PER PAGE
$total = count($array);
$numofpages = ceil($total / $numperpage); //TOTAL NUMBER OF PAGES
if(isset($array))
{
if (($currentpage > 0) && ($currentpages <= $numofpages))
{
//STARTING LOOP FOR ARRAY DATA
$start = ($currentpage-1) * $numperpage;
for($i=$start;$i<=($numperpage+$start-1);$i++)
{
///////////PLACE YOUR CODE HERE//////////////////////////
echo $array[$i] .'
';
////////////////////////////////////////////////////////
}
}
}
if ($currentpage != 1)
{ //GOING BACK FROM PAGE 1 SHOULD NOT BET ALLOWED
$previous_page = $currentpage - 1;
$previous = ' < ';
}
$pages = '';
for ($a=1; $a<=$numofpages; $a++)
{
if ($a == $currentpage)
$pages .= $a .' ';
else
$pages .= ''. $a .' ';
}
$pages = substr($pages,0,-1); //REMOVING THE LAST COMMA (,)
if ($currentpage != $numofpages)
{ //GOING AHEAD OF LAST PAGE SHOULD NOT BE ALLOWED
$next_page = $currentpage + 1;
$next = ' >';
}
echo '
'. $previous . $pages . $next; //PAGINATION LINKS
/////////////////////END OF ARRAY PAGINATION CODE/////////////////////
Do feel free to ask any questions that you may have concerns to web. No Compromise on Learning!
Saturday, March 29, 2014
Php Array Pagination Script
Subscribe to:
Post Comments (Atom)
How to change the PHP version for subfolders or subdomains
How to change the PHP version for subfolders or subdomains Setting a specific PHP version for a specific websites, subfolders or subdomain...
-
Welcome to the next part of OpenLayers 3 for Beginners! If you have not worked through parts one or two yet, you can hop over to them he...
-
Welcome to OpenLayers 3 for Beginners: Part 2. If you have not been to and completed OpenLayers 3 Part 1 yet, head over to http://chris...
-
Changing the Domainname: Yes, there is some form of "Search and Replace". To update WordPress options with the new blog locat...
No comments:
Post a Comment
Please Comment Here!