How to use large pagination in a limited area , plz see the bottom pictures , please help me ........
as an example in my page , i have more than 100 posts

no my pagination system is like this
1 2 3 4 5 6 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24

but i want to do like this , so please help me

1 2 3 4 5 6 8 9 10 11 22 23 24

non limited - [IMG]http://i31.tinypic.com/ztsmf7.jpg[/IMG]
limited - [IMG]http://i31.tinypic.com/28wp7ys.jpg[/IMG]
please help me ...........

Member Avatar for diafol

Just use your while loop to find the number of pages (as usual), then use some rules to display certain pages.

Do you want to display a maximum of 14 pages as suggested in your post? If so do you want the last 4 pages to link to the last pages?

1) If the total number of pages = 14 or less, display all page links.

2) Otherwise display the pages if the number is 10 or less OR display if the page number is greater than the total number of pages - 4.

I'm sure there are other formulae you could use.

Try the following code:

<style type="text/css">
A:link {font-weight:bold; font-family:"Arial";}
A:visited {font-weight:bold; font-family:"Arial";}
A:active {font-weight:bold; font-family:"Arial";}
A:hover {font-weight:bold; font-family:"Arial";}
</style>
<?
$number_of_pages=100; //maximum number of pages
$current_page=50; //set the current page probably with $_GET
for ($i=1;$i<=$number_of_pages;$i++) {
    if ($i<11) {
        echo ($i>1)? ' - ':''; // add dash between numbers.
        echo '<a href="index.php?id='.$i.'">'.$i.'</a>';
        }
    if (($i>=($current_page-1) && $i<=($current_page+1)) || $i>=($number_of_pages-2)) {
        echo ' - <a href="index.php?id='.$i.'">'.$i.'</a>';
        }
    }
?>
for($i = 1; $i <= $total_newspage; $i++)
{
      if(($newspage) == $i)
       {
            echo  "$i\n ";
       } 
       else 
      {
            echo  "<a href=\"news.php?newspage=$i\">$i</a>\n ";
      }
}

i am using this lines of code to generate my basic pagination , how to modify it to my needs . please .............

for($i = 1; $i <= $total_newspage; $i++)
{
      if(($newspage) == $i)
       {
            echo  "$i\n ";
       } 
       else 
      {
            echo  "<a href=\"news.php?newspage=$i\">$i</a>\n ";
      }
}

i am using this lines of code to generate my basic pagination , how to modify it to my needs . please .............

Why dont you explain the syntax you want when the middle page of 100 pages is selected. Example:

Page 50 selected - 100 pages total
[B].[/B]1  2  3  4  5  48  49  50  51  52  98  99  100

If you could show me a codebox like the above but your version of what the pegination should look like then I shall create it.

this is the full code i am using and it working perfect . what i want to do is , i have more than 100 pages ( '$total_newspage' ) but i want to display like this

1 2 3 4 5 6 7 8 9 10 ... 100 ALL

when i click on 10 , want to show like this

10 11 12 13 14 15 16 17 18 19 ... 100 ALL

and after 19

19 20 21 22 23 24 25 26 27 28 ... 100 ALL , and so on

now u got it what i want to do , plz help me

<?php


if(!isset($_GET['newspage'])){
$newspage = 1;
} else {
$newspage = $_GET['newspage'];
}


// Define the number of results per page
$max_results = 2;

// Figure out the limit for the query based
$from = (($newspage * $max_results) - $max_results);

$query_Record_data = "SELECT txtPostTitle, txtPostDate, txtPostContent, txtUsername FROM generic ORDER BY intPostID ASC LIMIT $from, $max_results";
$Record_data = mysql_query($query_Record_data, $mysql_Connection) or die(mysql_error());
$row_Record_data = mysql_fetch_assoc($Record_data);
$totalRows_Record_data = mysql_num_rows($Record_data);

// Figure out the total number of results in DB:
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM generic"),0);

// Figure out the total number of pages. Always round up using ceil()
$total_newspage = ceil($total_results / $max_results);

echo "<p style=\"clear:both;\" align=\"center\">\n";
echo $total_newspage;

?>
<?php   

//------------------ previous link----------------------
if($newspage > 1)
         {
            $prev = ($newspage - 1);
            echo  "<a href=\"apps.php?newspage=$prev\">‹‹ Previous</a>\n ";
			echo $i;
         }
		 
//----------Displaying pagination bar---------------	     
       
         for($i = 1; $i <= $total_newspage ; $i++)
         {
            if(($newspage) == $i)
            {
               echo  "$i\n ";
            } 
			else 
			{
               echo  "<a href=\"apps.php?newspage=$i\">$i</a>\n ";
            }
         }

//-------------- Build Next Link ------------------------------------------	 
        
         if($newspage < $total_newspage)
         {
            $next = ($newspage + 1);
			
            echo  "<a href=\"apps.php?newspage=$next\">Next ››</a>\n";
         }
echo "</p>\n"; 

?>

now u got it what i am trying to do , plz help me

Try the following:

<?
$number_of_pages=100; //maximum number of pages
$current_page=$_GET['newspage']; //set the current page

//set above variables
//don't change the below
$tmp=$current_page+10;
for ($i=1;$i<=$number_of_pages;$i++) {
    if (($i>=($current_page-1) && $i<($tmp)) || $i==$number_of_pages) {
        echo '<a href="index.php?newspage='.$i.'">'.$i.'</a>';
        echo (($i<($tmp) && ($tmp)<=$number_of_pages) || ($i<($tmp) && $currentpage<$number_of_pages))? ' - ':''; // add dash between numbers.
        }
    }
?>

I use this function to paginate:

<?php 
if(isset($_GET["page"])) {
$page = $_GET["page"];
} else {
$page = 1;
}
$totalPages = 1000;
function paging($page, $totalPages) {
	$printPages = 7; //Show only X pages
	$i = 1;
	$previous_page = ($page > 1) ? $page - 1 : 1;
	$next_page = $page + 1;
	if($totalPages < $printPages) {
		$printPages = $totalPages;
	}
echo '<div class="pagination" align="center">
<ul>';
	if($page > 1) {
		echo ' <li><a href="?page=1">&laquo;&laquo; First</a></li> ';
		echo ' <li><a href="?page='.$previous_page.'">&laquo; Prev</a></li> ';
		if($totalPages > 0) {
//Nothing for now, used to have a  |  separator here
		}
	}

	if($page - 3 <= 0)
	{
		$currentPage = 1;
	}
	elseif($page > 3 && $page + 3 < $totalPages)
	{
		$currentPage = $page - 3;
	}
	else
	{
		$currentPage = $totalPages - ($printPages - 1);
	}

	while($i <= $printPages)
	{
		echo '<li><a';
		if($page == $currentPage) {
		echo ' class="currentpage" ';
		}
		echo ' href="?page='.$currentPage.'"> '.$currentPage.' </a></li>&nbsp;';
		$currentPage++;
		$i++;
	}

	if($page < $totalPages)
	{
	$next = $page + 1;
		echo '&nbsp;<li><a href="?page='.$next.'">Next &raquo;</a></li>  ';
		echo ' <li> <a href="?page='.$totalPages.'">Last &raquo;&raquo;</a></li>  ';

	}
	echo '</ul></div>';
}

//Use it
paging($page, $totalPages)
?>

EDITED Now its better!


You can mod. it for you...

p.s. This is used for styling:
http://www.dynamicdrive.com/style/csslibrary/item/css_pagination_links/#

hi friend thanks for u r help and this code , it is working perfect

but i am confused while implementing , my idea , following

this is my pagination bar
---------------------------
1 2 3 4 5 6 7 8 9 .. 98 99 100


when i click on 9th page [ here my $printPages = 9 ] , i want to increment $page ( $page = $page+9) , means i want to display like this

9 10 11 12 13 14 15 16 17 ... 98 99 100

17 18 19 20 21 22 23 24 25 .. 98 99 100
and so on

please help me , i am very confused , so plz help me

plz anybody help me.................

Currently, when you're on Page 9, the link is displayed like this:

«« First « Prev 6 7 8 9 10 11 12 13 14 Next » Last »»

This is better, cuz the visitor will have the last 3 previous page, and the next 5 pages...
So You want this:
«« First « Prev 9 10 11 12 13 14 15 16 17 Next » Last »»

When you're on page9 right?

EDIT{}

Here:

<style type="text/css">
.pagination{
padding: 2px;
}
.pagination ul{
margin: 0;
padding: 0;
text-align: left; /*Set to "right" to right align pagination interface*/
font-size: 16px;
}
.pagination li{
list-style-type: none;
display: inline;
padding-bottom: 1px;
}
.pagination a, .pagination a:visited{
padding: 0 5px;
border: 1px solid #9aafe5;
text-decoration: none; 
color: #2e6ab1;
}
.pagination a:hover, .pagination a:active{
border: 1px solid #2b66a5;
color: #000;
background-color: #FFFF80;
}
.pagination a.currentpage{
background-color: #2e6ab1;
color: #FFF !important;
border-color: #2b66a5;
font-weight: bold;
cursor: default;
}
.pagination a.disablelink, .pagination a.disablelink:hover{
background-color: white;
cursor: default;
color: #929292;
border-color: #929292;
font-weight: normal !important;
}
.pagination a.prevnext{
font-weight: bold;
}
</style>
<?php 
if(isset($_GET["page"])) {
$page = $_GET["page"];
} else {
$page = 1;
}
$totalPages = 50;
function paging($page, $totalPages) {
	$printPages = 9; //Show only X pages
	$i = 1;
	$previous_page = ($page > 1) ? $page - 1 : 1;
	$next_page = $page + 1;
	if($totalPages < $printPages) {
		$printPages = $totalPages;
	}
echo '<div class="pagination" align="center">
<ul>';
	if($page > 1) {
		echo ' <li><a href="?page=1">&laquo;&laquo; First</a></li> ';
		echo ' <li><a href="?page='.$previous_page.'">&laquo; Prev</a></li> ';
		if($totalPages > 0) {
//Nothing for now, used to have a  |  separator here
		}
	}

	if($page - $printPages <= 0) 
	{
		$currentPage = 1;
	}
	elseif($page > 3 && $page + ($printPages -1) < $totalPages)
	{
		$currentPage = $page;
	}
	else
	{
		$currentPage = $totalPages - ($printPages - 1);
	}
	

	while($i <= $printPages)
	{
		echo '<li><a';
		if($page == $currentPage) {
		echo ' class="currentpage" ';
		}
		echo ' href="?page='.$currentPage.'"> '.$currentPage.' </a></li>&nbsp;';
		$currentPage++;
		$i++;
	}

	if($page < $totalPages)
	{
	$next = $page + 1;
		echo '&nbsp;<li><a href="?page='.$next.'">Next &raquo;</a></li>  ';
		echo ' <li> <a href="?page='.$totalPages.'">Last &raquo;&raquo;</a></li>  ';

	}
	echo '</ul></div>';
}

//Use it
paging($page, $totalPages)
?>

plz , i am waiting for some help . Please............

Look at the post above yours mate! i posted the code, didn't it work????

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.