Jump to content

Recommended Posts

So I wrote part of this code, and found other parts of it on the net. Basically it's a PHP paging script and it lets me break up my queries into multiple pages. Basically right now all it does is shows the pages at the bottom, and shows a number for every single page it can show. Example:

 

2qau71x.png

 

So, basically what I want to do is be able to maybe tone it down a little by maybe only showing only 4 numbers before the current number and 4 after it? And have some sort of "..." and then show the final page number? Anyway I just want to clean this code up a bit. Can anyone help? The ideal result will be something like digg.com's (scroll to the bottom of the page). you can see how they have a "..." and then show a button for the last page...

 

Something like this (say i'm on page 45)

 

[previous] [1] ... 41 42 43 44 [45] 46 47 48 49 ... [143] [next]

 

 

Do you understand? If not then please ask me questions. I'm not sure how to get this rolling! Thank you so much in advance I appreciate it!

 

 

		$max = 10;
		$num = $page * $max - $max;
		$totalpage = ceil($lines / $max) + 1;
                        $page = 1;

		if ($page > 1) 
		{
     			   echo "<a href=\"?action=index&p=".($page-1)."\"><span id=\"paging\">Previous</span></a> \n";
    			}
		else if($page <= 1)
		{
		   echo "<span id=\"paging\">Previous</span> \n";
		}

    			for($i = 1; $i < $totalpage; $i++) 
		{
        			if($i == $page) 
			{
           				echo "<span id=\"paging\">$i</span> \n";
       				}
			else 
			{
            				echo "<a href=\"?action=index&p=".$i."\"><span id=\"paging\">$i</span></a> \n";
        			}
    			}

    			if ($page < $totalpage - 1) 
		{
        			echo "<a href=\"?action=index&p=".($page + 1)."\"><span id=\"paging\">Next</span></a>\n";
    			}
		else if($page >= $totalpage - 1)
		{
			echo "<span id=\"paging\">Next</span>\n";
		}	

Link to comment
https://forums.phpfreaks.com/topic/142736-little-php-paging-help/
Share on other sites

         $max = 10;
         $num = $page * $max - $max;
         $totalpage = ceil($lines / $max) + 1;
                       // $page = 1;
$show = 9;
$start = (int) max(1, min($page - floor(($show - 1)/2), $totalpage - $show + 1));
$end = min($totalpage, $start + $show - 1);


         if ($page > 1)
         {
                 echo "<a href=\"?action=index&p=".($page-1)."\"><span id=\"paging\">Previous</span></a> \n";
             }
         else if($page <= 1)
         {
            echo "<span id=\"paging\">Previous</span> \n";
         }
             for($i = $start; $i <= $end; $i++)
         {
                 if($i == $page)
            {
                       echo "<span id=\"paging\">$i</span> \n";
                   }
            else
            {
                        echo "<a href=\"?action=index&p=".$i."\"><span id=\"paging\">$i</span></a> \n";
                 }
             }

             if ($page < $totalpage - 1)
         {
                 echo "<a href=\"?action=index&p=".($page + 1)."\"><span id=\"paging\">Next</span></a>\n";
             }
         else if($page >= $totalpage - 1)
         {
            echo "<span id=\"paging\">Next</span>\n";
         }   

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.