Jump to content

pagination help


davieboy

Recommended Posts

Hi all

 

Im using the pagination successfully, but now i do have quite alot of pages being given in results

 

eg

PREV15 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 NEXT15

 

im using the standard

 

<?php 
include("config.php"); 
mysql_connect($db_host,$db_user,$db_pass);
mysql_select_db ($db_name) or die (mysql_error());
    $limit          = 15;                  
    $query_count    = "SELECT * FROM photos WHERE status = 'accepted'";       
    $result_count   = mysql_query($query_count);       
    $totalrows      = mysql_num_rows($result_count);    
    
    $PHP_SELF    =    $_SERVER['PHP_SELF']; 
       
    if(!isset($_GET['page'])){ // Checks if the $page variable is empty (not set) 
        $page = 1;     // If it is empty, we're on page 1 
    } else{ 
          
        $page = $_GET['page']; 
    } 
     
           

    $limitvalue = $page * $limit - ($limit);    
    // Ex: (page2 * 5(items per page) = 10) - 5 = 5 <- data starts at 5 

 

and after my content

 





    if($page != 1){    
        $pageprev = $page - 1; //decrementing $page-- does not work on all php configurations. 
          
           
        echo("<a href=\"$PHP_SELF?page=$pageprev\"><b>PREV</b>".$limit."</a> ");    
    }else{ 
        echo("PREV".$limit." "); 
    } 

    $numofpages = $totalrows / $limit;    
     
      
    #echo "<br>", $totalrows; 
   #exit; 
       
    for($i = 1; $i <= $numofpages; $i++){ 
        /* This for loop will add 1 to $i at the end of each pass until $i is greater    
        than $numofpages. */ 
        if($i == $page){ 
            echo($i." "); 
        }else{ 
            echo("<a href=\"$PHP_SELF?page=$i\">$i</a> "); 
        } 
    } //code above has been decoded lozza 


    if(($totalrows % $limit) != 0){ 
        if($i == $page){ 
            echo($i." "); 
        }else{ 
            echo("<a href=\"$PHP_SELF?page=$i\">$i</a> "); 
        } 
    } 

    if(($totalrows - ($limit * $page)) > 0){ 
        $pagenext = $page + 1; //incrementin $page like $page++ does not work in all enviroments 
            
        echo("<a href=\"$PHP_SELF?page=$pagenext\"><b>NEXT</b>".$limit."</a>");    
    }else{ 
        echo("NEXT".$limit);    
    } 
       
    mysql_free_result($result); 
?>

 

Just wondering how i can limit the results to say 10->15 pages and have the next and previous links on the end

eg instead of the above have

 

PREV15 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 NEXT15

 

Thanks to all

 

David

Link to comment
Share on other sites

  • 1 month later...
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.