Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 6 of 6
  1. #1
    Junior Member
    Join Date
    Feb 2010
    Posts
    2
    Member #
    21213
    I am having trouble listing the page numbers at the bottom of my page. The site is ijustwanttotellyou.com. Currently, every page is listed at the bottom surrounded by 'Previous' and 'Next'. What I'm trying to do is, like most sites with multiple pages, have 'Previous 2 3 4 5 .... 400 Next' (depending on what page is being viewed).

    This is my current code for the page numbers and I can't figure out what to change:


    if ($back >=0) {

    $links .= '<a href="?page='.$back.$catdynamic.'"><p class="pagenumber">Previous Page</p></a> ';

    }

    $i = 0;

    $x = 1;


    for ($i=0;$i < $total_rows;$i=$i+$limit){


    if($i != $eu){

    $links .= '<a href="?page='.$i.$catdynamic.'"><span class="white">'.$x.'</a></span> ';

    }

    else {

    $links .= '<b><span class="grey">'.$x.'</b></span> ';

    }


    $x = $x+1;


    }


    if ($whathis < $total_rows) {

    $links .= ' <a href="?page='.$next.$catdynamic.'"><p class="anynamehere">Next Page</p></a>';

    }

  2.  

  3. #2
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    Ok, here's a little pagination script I use a lot.... I think you can figure out what maps to what:
    PHP Code:
    <div class="pagination">
    <?php
       
    if ($params->count 1)
         {

        
    // Pagination Component
        
    $pages ceil($params->count $params->perPage);

        
    $page $params->page;
        
    $prev $page 1;
        
    $next $page 1;

        
    $uri $GLOBALS["uri"];

        
    $startPageCnt max(1$page-5);
        
    $endPageCnt max($page 511);
        
    $endPageCnt min($endPageCnt$pages);

            
    $endRecord min($params->stop $params->page$params->count);

            if (
    $pages 0)
            {
          if (
    true || $params->displayPage) {
            if (
    $endRecord 0)
              print(
    "<p><span><strong>Showing " . ($params->start+1) . " to " . ($endRecord) . " of {$params->count} matches.</strong></span></p><p>");
            else
              print(
    "<p><span><strong>Page {$page} of {$pages} </strong></span>");
          }

          if (
    $pages 1) {    
            if (
    $page 1) {
              
    $uri->setParam("page"$prev);
              print(
    "<span><a href=\"{$uri}\"><u>Previous</u></a> | </span>");
            }
            for (
    $i $startPageCnt$i <= $endPageCnt$i++) {
              if (
    $i == $page) {
            print(
    "<span style=\"font-weight: bold\">{$i}</span>");
              } else {
            
    $uri->setParam("page"$i);
            print(
    "<span><a href=\"{$uri}\">{$i}</a></span>");
              }
              if (
    $i $pages && $i != $endPageCnt) {
            print(
    "<span> | </span>");
              }
            }
            if (
    $page $pages) {
              
    $uri->setParam("page"$next);
              print(
    "<span> | <a href=\"{$uri}\"><u>Next</u></a></span>");
            }
          }
          print(
    "</p>");
        }
    {
    $params->count}]</p>");
         }

    ?>
    </div>

  4. #3
    Junior Member
    Join Date
    Feb 2010
    Posts
    2
    Member #
    21213
    I tried my hardest to use your script and change the variables to fit within mine...but for the life of me, I couldn't figure it out...

  5. #4
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    hmm... ok, well some of it is object oriented, based on the Qi framework.

    I'll try to reduce it to simple variables
    PHP Code:
    <div class="pagination">
    <?php
    // Pagination Component
    $count 100// Number of items - you should get this from your query results
    $page $_REQUEST["p"] ? $_REQUEST["p"] : 1;  // Current page, )default to 1)
    $perPage $_REQUEST["pp"] ? $_REQUEST["pp"] : 10;  // Show per page (default 10)
    $pages ceil($count $perPage); // Number of total pages to display
    $prev $page 1;
    $next $page 1;

    $uri "/path/to/this/page.php?pp={$perPage}";

    $startPageCnt max(1$page-5);
    $endPageCnt max($page 511);
    $endPageCnt min($endPageCnt$pages);
    $startRecord = ($page-1)*$perPage+1;
    $endRecord min($count$page*$perPage);

    if (
    $pages 0) {
        print(
    "<p>Showing {$startRecord} to {$endRecord} of {$count} matches.</p>");

        if (
    $pages 1) {    
            if (
    $page 1) print("<span><a href=\"{$uri}&p={$prev}\"><u>Previous</u></a> | </span>");
            for (
    $i $startPageCnt$i <= $endPageCnt$i++) {
                if (
    $i == $page) {
                    print(
    "<span style=\"font-weight: bold\">{$i}</span>");
                } else {
                    print(
    "<span><a href=\"{$uri}&p={$i}\"><u>Previous</u></a> | </span>");
                }
                if (
    $i $pages && $i != $endPageCnt) {
                    print(
    "<span> | </span>");
                }
            }
            if (
    $page $pages) print("<span><a href=\"{$uri}&p={$next}\"><u>Next</u></a> | </span>");
        }
        print(
    "</p>");
    }

    ?>
    </div>

  6. #5
    Senior Member
    Join Date
    Dec 2008
    Posts
    483
    Member #
    17875
    Liked
    1 times
    http://scottmoniz.com/programmingBlo...ing-using-php/

    Should take you a few minutes to setup. Works out of the box, easy to restyle, etc etc.

  7. #6
    Senior Member
    Join Date
    Dec 2008
    Posts
    483
    Member #
    17875
    Liked
    1 times
    print '<div class="paging"><ul>';
    $prevpg=$pg-1;
    if($prevpg>0){
    print '<li><a href="?pg='.$prevpg.'" class="prev">Prev</a></li>';
    }

    for($i=1; $i<=$maxpage; $i++){
    if($pg==$i)
    print '<li><span>'.$i.'</span></li>';
    else{
    $qs="?pg=".$i;
    $qs.=($catID > 0 ? "&cid=".$catID : "");
    print '<li><a href="'.$qs.'">'.$i.'</a></li>';
    }
    }
    $nextpg=$pg+1;
    if($nextpg<=$maxpage){
    print '<li><a href="?pg='.$nextpg.'" class="next">Next</a></li>';
    }
    print "</ul></div>";

    This supports the prev/next.
    There ARE some limitations, but if you just need simple prev/next 1-x paging, this works perfect. the 1 thing it doesnt support is keeping query string vars, so ...choose w/e u need enjoy


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 12:14 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com