Results 1 to 3 of 3
  1. #1
    Action Jackson - King of the World
    Join Date
    January 18th, 2005
    Posts
    2,201
    I've been working on this since yesterday but get stuck on the links to the 3rd of the next 5 pages. I think the problem is with the $n variable but not sure why. Any suggestions?


    <?


    $total_row=mysql_num_rows($result_count);
    $limit_row=5;

    if (!$page){ $page=1;}
    $total_page=ceil($total_row/$limit_row);
    $row_begin=$limit_row*($page-1);
    if($page==$total_page&&($total_row%$limit_row)){
    $read_row=($total_row%$limit_row);
    }else{$read_row=$limit_row;}
    if($total_page<=5){
    $page_begin=0;
    $page_end=$total_page;
    $page5=1;
    $newpage5=1;
    }else{

    $page5=ceil($total_page/5);
    if($newpage5 ==""){$newpage5=1;}
    $page_begin=5*($newpage5-1);
    if($newpage5==1)
    {
    if($newpage5==($page5-1)&&($total_page%5))
    {
    $page_endx=$total_page%5;
    $page_end=5;
    echo "<FONT FACE=ARIAL SIZE=2>| Pre 5 pages | <A HREF=\"domestics.php?interest=$interest&newpage5=2&&page=6\"> page $page_endx </A> |</FONT>";
    }else{
    $page_end=5;
    echo "<FONT FACE=ARIAL SIZE=2>| head | <A HREF=\"domestics.php?interest=$interest&newpage5=2&&page=6\">next 5 page</A> |</FONT>";
    }
    }elseif($newpage5>1){
    if($newpage5==$page5&&($total_page%5))
    {$page_end=$total_page%5;
    echo "<FONT FACE=ARIAL SIZE=2>| <A HREF=\"domestics.php?interest=$interest&newpage5=".($newpage5-1)."&&page=".(($newpage5-2)*5+1)."\">Pre 5 pages</A> |end $page_end |</FONT>";
    }else{
    if($newpage5==($page5-1)&&($total_page%5))
    { $page_endx=$total_page%5;
    $page_end=5;
    echo "<FONT FACE=ARIAL SIZE=2>|<a href=\"domestics.php?interest=$interest&newpage5=".($newpage5-1)."&&page=".(($newpage5-2)*5+1)."\"> pre 5 page</a> | <A HREF=\"domestics.php?interest=$interest&newpage5=".($newpage5+1)."&&page=".($newpage5*5+1)."\"> page $page_endx </A> |</FONT>";
    } else{
    $page_end=5;
    echo "<FONT FACE=ARIAL SIZE=2>| <A HREF=\"domestics.php?interest=$interest&newpage5=".($newpage5-1)."&&page=".(($newpage5-2)*5+1)."\">pre 5 page</A> | <A HREF=\"domestics?interest=$interest&newpage5=".($newpage5+1)."&&page=".($newpage5*5+1)."\">next 5 page</A> |</FONT>";
    }
    }

    }
    }

    //----------------------5 pages--------------------------------------
    echo "total£º".$total_row."";
    for ($n=$page_begin+1;$n<=$page_begin+$page_end;$n++){
    echo "<a href=domestics.php?interest=$interest&newpage5=$newpage5&&page=$n >$n</a>";
    }
    echo "page";

    ?>

  2. #2
    Member
    Join Date
    January 18th, 2005
    Posts
    69
    Try this

    <?


    $total_row=mysql_num_rows($result_count);
    $limit_row=5;

    if (!$page){ $page=1;}
    $total_page=ceil($total_row/$limit_row);
    $row_begin=$limit_row*($page-1);
    if($page==$total_page&&($total_row%$limit_row)){
    $read_row=($total_row%$limit_row);
    }else{$read_row=$limit_row;}
    if($total_page<=5){
    $page_begin=0;
    $page_end=$total_page;
    $page5=1;
    $newpage5=1;
    }else{

    $page5=ceil($total_page/5);
    if($newpage5 ==""){$newpage5=1;}
    $page_begin=5*($newpage5-1);
    if($newpage5==1)
    {
    if($newpage5==($page5-1)&&($total_page%5))
    {
    $page_endx=$total_page%5;
    $page_end=5;
    echo "<FONT FACE=ARIAL SIZE=2>| Pre 5 pages | <A HREF=\"domestics.php?interest=$interest&newpage5=2&&page=6\"> page $page_endx </A> |</FONT>";
    }else{
    $page_end=5;
    echo "<FONT FACE=ARIAL SIZE=2>| head | <A HREF=\"domestics.php?interest=$interest&newpage5=2&&page=6\">next 5 page</A> |</FONT>";
    }
    }elseif($newpage5>1){
    if($newpage5==$page5&&($total_page%5))
    {$page_end=$total_page%5;
    echo "<FONT FACE=ARIAL SIZE=2>| <A HREF=\"domestics.php?interest=$interest&newpage5=".($newpage5-1)."&&page=".(($newpage5-2)*5+1)."\">Pre 5 pages</A> |end $page_end |</FONT>";
    }else{
    if($newpage5==($page5-1)&&($total_page%5))
    { $page_endx=$total_page%5;
    $page_end=5;
    echo "<FONT FACE=ARIAL SIZE=2>|<a href=\"domestics.php?interest=$interest&newpage5=".($newpage5-1)."&&page=".(($newpage5-2)*5+1)."\"> pre 5 page</a> | <A HREF=\"domestics.php?interest=$interest&newpage5=".($newpage5+1)."&&page=".($newpage5*5+1)."\"> page $page_endx </A> |</FONT>";
    } else{
    $page_end=5;
    echo "<FONT FACE=ARIAL SIZE=2>| <A HREF=\"domestics.php?interest=$interest&newpage5=".($newpage5-1)."&&page=".(($newpage5-2)*5+1)."\">pre 5 page</A> | <A HREF=\"domestics.php?interest=$interest&newpage5=".($newpage5+1)."&&page=".($newpage5*5+1)."\">next 5 page</A> |</FONT>";
    }
    }

    }
    }

    //----------------------5 pages--------------------------------------
    echo "total£º".$total_row." ";
    for ($n=$page_begin+1;$n<=$page_begin+$page_end;$n++){
    echo "<a href=domestics.php?interest=$interest&newpage5=$newpage5&&page=$n >$n</a> ";
    }
    echo "page";

    ?>

  3. #3
    Newbie
    Join Date
    January 18th, 2005
    Posts
    46
    Hi Jack,

    I use the following;

    <pre class="ip-ubbcode-code-pre"># NUMBER_OF_HITS | MAX_HITS | NUM_ENTRIES | SCRIPT URL
    # I define $url with: my $url = CGI-&gt;url( path_info =&gt; '1' );
    &custom_toolbar($sent_nh,$sent_mh,$vars-&gt;{sent_num_messages},$url);
    </pre>

    ...and the following routine;

    <pre class="ip-ubbcode-code-pre">sub custom_toolbar {
    # ---------------------------------------------------------------
    # Display/calculate a "next hits" toolbar.
    #
    my $class = $Plugins::GForum::PMManager;
    my ($nh, $maxhits, $numhits, $script,$do_sent) = @_;
    my ($next_url, $max_page, $next_hit, $prev_hit, $left, $right, $upper, $lower, $first, $url, $last, $i);

    # Return if there shouldn't be a speedbar.
    return unless ($numhits &gt; $maxhits);

    # Strip nh=\d out of the query string, as we need to append it on. Try and keep
    # the url looking nice (i.e. no double ;&, or extra ?.
    $script =~ s/[&;]nh=\d+([&;]?)/$1/;
    ($script =~ /\?/) or ($script .= "?");
    $next_hit = $nh + 1;
    $prev_hit = $nh - 1;
    $maxhits ||= 25;
    $max_page = int ($numhits / $maxhits) + (($numhits % $maxhits) ? 1 : 0);

    # First, set how many pages we have on the left and the right.
    $left = $nh; $right = int($numhits/$maxhits) - $nh;
    # Then work out what page number we can go above and below.
    ($left &gt; 7) ? ($lower = $left - 7) : ($lower = 1);
    ($right &gt; 7) ? ($upper = $nh + 7) : ($upper = int($numhits/$maxhits) + 1);
    # Finally, adjust those page numbers if we are near an endpoint.
    (7 - $nh &gt;= 0) and ($upper = $upper + (8 - $nh));
    ($nh &gt; ($numhits/$maxhits - 7)) and ($lower = $lower - ($nh - int($numhits/$maxhits - 7) - 1));
    $url = "";
    # Then let's go through the pages and build the HTML.
    ($nh &gt; 1) and ($url .= qq~&lt;a href="$script;nh=1"&gt;[&lt;&lt;]&lt;/a&gt; ~);
    ($nh &gt; 1) and ($url .= qq~&lt;a href="$script;nh=$prev_hit"&gt;[&lt;]&lt;/a&gt; ~);
    for ($i = 1; $i &lt;= int($numhits/$maxhits) + 1; $i++) {
    if ($i &lt; $lower) { $url .= " ... "; $i = ($lower-1); next; }
    if ($i &gt; $upper) { $url .= " ... "; last; }
    ($i == $nh) ?
    ($url .= qq~$i ~) :
    ($url .= qq~&lt;a href="$script&amp;nh=$i"&gt;$i&lt;/a&gt; ~);
    if ($i * $maxhits == $numhits) { $nh == $i and $next_hit = $i; last; }
    }
    $url .= qq~&lt;a href="$script;nh=$next_hit"&gt;[&gt;]&lt;/a&gt; ~ unless ($next_hit == $nh or ($nh * $maxhits &gt; $numhits));
    $url .= qq~&lt;a href="$script;nh=$max_page"&gt;[&gt;&gt;]&lt;/a&gt; ~ unless ($next_hit == $nh or ($nh * $maxhits &gt; $numhits));
    return $url;
    }</pre>

    Works very well for me

    Hope that helps.

    Cheers

    Andy

  4. Newsletter Signup

+ Reply to Thread

Similar Threads

  1. pagination within a category
    By Sharan in forum Programming / Datafeeds / Tools
    Replies: 0
    Last Post: August 18th, 2010, 04:18 PM
  2. Pagination
    By drumminlogan in forum PopShops
    Replies: 6
    Last Post: November 21st, 2008, 06:01 PM
  3. Pagination
    By jackson992 in forum Programming / Datafeeds / Tools
    Replies: 1
    Last Post: January 2nd, 2008, 08:46 AM
  4. Pagination change
    By msladybug in forum PopShops
    Replies: 7
    Last Post: November 29th, 2007, 10:26 AM
  5. Using webmerge for pagination
    By dak142 in forum WebMerge (Fourthworld.com)
    Replies: 1
    Last Post: July 22nd, 2004, 07:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •