1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Need help fixing my pagination!

Discussion in 'Programming' started by Kurt Whittingham, May 7, 2012.

  1. #1
    I am trying to put pagination into pages of my site.. this is what i have got so far

    Page i want pagination on (the pagination boxes show up just dont work)=
    PHP:
    1. <?php
    2.  
    3.     require('connect.php');
    4.  
    5.     $page   = intval($_GET['page']);
    6.     $tpages = ($_GET['tpages']) ? intval($_GET['tpages']) : 10; // 20 by default
    7.     $adjacents  = intval($_GET['adjacents']);
    8.     if($page<=0)  $page  = 1;
    9.     if($adjacents<=0) $adjacents = 4;
    10.     $reload = $_SERVER['PHP_SELF'] . "?tpages=" . $tpages . "&amp;adjacents=" . $adjacents;
    11.    
    12.     $result = mysql_query("SELECT * FROM articles WHERE category_id='1' ORDER BY article_id DESC")
    13.     or die(mysql_error());  
    14.    
    15.     echo "<table width='100%' cellspacing='10'>";
    16.     // keeps getting the next row until there are no more to get
    17.     while($row = mysql_fetch_array( $result )) {
    18.     // Print out the contents of each row into a table
    19.     echo "<tr><td>";
    20.     // arrow
    21.     echo ("<img src='arrow.gif'>"); echo "&nbsp;&nbsp;";
    22.     // article name
    23.     echo '<a style="font-size: 20px" href="'. $row['url'] .'">'. $row['article_name'] .'</a>';
    24.     echo "</td></tr><tr><td>";
    25.     // author + date
    26.     echo $row['author']; echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"; echo $row['date'];
    27.     echo "</td></tr><tr><td>";
    28.     // Description
    29.     echo "Brief Decription : "; echo "&nbsp;&nbsp;"; echo $row['description'];
    30.     echo "<hr /></td></tr>";
    31. }
    32.  
    33.  
    34.             echo "<tr><td>";
    35.            
    36.             include("pagination3.php");
    37.             echo paginate_three($reload, $page, $tpages, $adjacents);
    38.            
    39.             echo "</td></tr>";
    40. ?>
    Pagination page =
    PHP:
    1. <?php
    2. /*************************************************************************
    3. php easy :: pagination scripts set - Version Three
    4. ==========================================================================
    5. Author:      php easy code, www.phpeasycode.com
    6. Web Site:    http://www.phpeasycode.com
    7. Contact:     webmaster@phpeasycode.com
    8. *************************************************************************/
    9. function paginate_three($reload, $page, $tpages, $adjacents) {
    10.    
    11.     $prevlabel = "&lsaquo; Prev";
    12.     $nextlabel = "Next &rsaquo;";
    13.    
    14.     $out = "<div class=\"pagin\">\n";
    15.    
    16.     // previous
    17.     if($page==1) {
    18.         $out.= "<span>" . $prevlabel . "</span>\n";
    19.     }
    20.     elseif($page==2) {
    21.         $out.= "<a href=\"" . $reload . "\">" . $prevlabel . "</a>\n";
    22.     }
    23.     else {
    24.         $out.= "<a href=\"" . $reload . "&amp;page=" . ($page-1) . "\">" . $prevlabel . "</a>\n";
    25.     }
    26.    
    27.     // first
    28.     if($page>($adjacents+1)) {
    29.         $out.= "<a href=\"" . $reload . "\">1</a>\n";
    30.     }
    31.    
    32.     // interval
    33.     if($page>($adjacents+2)) {
    34.         $out.= "...\n";
    35.     }
    36.    
    37.     // pages
    38.     $pmin = ($page>$adjacents) ? ($page-$adjacents) : 1;
    39.     $pmax = ($page<($tpages-$adjacents)) ? ($page+$adjacents) : $tpages;
    40.     for($i=$pmin; $i<=$pmax; $i++) {
    41.         if($i==$page) {
    42.             $out.= "<span class=\"current\">" . $i . "</span>\n";
    43.         }
    44.         elseif($i==1) {
    45.             $out.= "<a href=\"" . $reload . "\">" . $i . "</a>\n";
    46.         }
    47.         else {
    48.             $out.= "<a href=\"" . $reload . "&amp;page=" . $i . "\">" . $i . "</a>\n";
    49.         }
    50.     }
    51.    
    52.     // interval
    53.     if($page<($tpages-$adjacents-1)) {
    54.         $out.= "...\n";
    55.     }
    56.    
    57.     // last
    58.     if($page<($tpages-$adjacents)) {
    59.         $out.= "<a href=\"" . $reload . "&amp;page=" . $tpages . "\">" . $tpages . "</a>\n";
    60.     }
    61.    
    62.     // next
    63.     if($page<$tpages) {
    64.         $out.= "<a href=\"" . $reload . "&amp;page=" . ($page+1) . "\">" . $nextlabel . "</a>\n";
    65.     }
    66.     else {
    67.         $out.= "<span>" . $nextlabel . "</span>\n";
    68.     }
    69.    
    70.     $out.= "</div>";
    71.    
    72.     return $out;
    73. }
    74. ?>
    But the pagination doesnt work, i was trying with 5 entries a page, then it would go to page2 etc etc.. but couldnt get it to work.

    any help would be awesome
     
    Kurt Whittingham, May 7, 2012 IP