Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Showing Pagebreak Navigation on top and bottom of pages before foreceach statement?

by Baffled (Acolyte)
on Aug 05, 2011 at 04:32 UTC ( #918678=perlquestion: print w/ replies, xml ) Need Help??
Baffled has asked for the wisdom of the Perl Monks concerning the following question:

OK here is my delima that I seek the wisdom of the monks on. I have a page navigation bar at the bottom of the page that the client has asked appear on the top as well as the bottom of the page. Seems simple so far...

However I find on the first page (page=0) that the top navigation does not work, but works fine on the 2nd and additional pages. The foreach statement comes in after the top header and I believe that it because it has not counted the items and pages yet and that is why it is not able to show the pages correctly on the first page. I have tried over and over to maybe move the count higher in the page before where I would place the page count bar but to no avail.

To see the page in question that is generated from the following code simply go to 2bidlive DOT com and click on "Enter The Auction" and you will see what Im talking about. I have left it as is so you can see when you click onto the next page from the bottom then the top will work.

my $nowtime = localtime int($config{'time'}); opendir THEDIR, "$config{'basepath'}$form{'category'}" or &oops("C +ategory directory $form{'category'} could not be opened."); my @allfiles = grep -T, map "$config{'basepath'}$form{'category'}/ +$_", sort { int($a) <=> int($b) } (readdir THEDIR); closedir THEDIR; my $file; my @cellcolor=($config{'odd_row_color'},$config{'even_row_color'}) +; my $color = 0; my $pagebreak = int $form{pb} || 30; my ($icount, $pcount) = (0,0); print "<div align=center><center><table height=30 border=1 cellpad +ding=0 cellspacing=0 width=100% bordercolor=$config{'bordercolor'}>\n +"; print "<tr><td align=center width=100% bgcolor=$config{'colortable +head0'}><font face=arial size=3>&nbsp;<font color=$config{'text0'}><b +>All Items - $category{$form{'category'}}</b></td></tr></table></cent +er></div>\n"; print "<font face=arial size=3><div align=center><center><table bor +der=0 cellpadding=0 cellspacing=0 width=100%><tr><td width=100% bgcol +or=$config{'colortablehead0'} height=3></td></tr></table></center></d +iv><br>\n"; pagebreak($pcount,$pagebreak); # This is where I have t +he top pagebreak navigation bar print "<BR><BR>\n" print "<table border=0 cellpadding=1 cellspacing=2 width=100% borderc +olor=$config{'bordercolor'}>\n"; print "<TR><TD ALIGN=CENTER BGCOLOR=$config{'colortablehead0'} WID +TH=12\%><font color=$config{'text0'} face=arial size=2><B>Status</B>< +/font><TD ALIGN=CENTER BGCOLOR=$config{'colortablehead0'} width=40\%> +<font color=$config{'text0'} face=arial size=2><B>All Items - $catego +ry{$form{'category'}}</B></font></TD><TD ALIGN=CENTER BGCOLOR=$config +{'colortablehead0'} width=6\%><font color=$config{'text0'} face=arial + size=2><B>Price</B></font></TD><TD ALIGN=CENTER BGCOLOR=$config{'col +ortablehead0'} width=5\%><font color=$config{'text0'} face=arial size +=2><B>Bids</B></font></TD><TD ALIGN=CENTER BGCOLOR=$config{'colortabl +ehead0'} width=14\%><font color=$config{'text0'} face=arial size=2><B +>High Bidder</B></font></TD><TD ALIGN=CENTER BGCOLOR=$config{'colorta +blehead0'} width=10\%><font color=$config{'text0'} face=arial size=2> +<B>Closes $config{'timezone'}</B></font></TD><TD ALIGN=CENTER BGCOLOR +=$config{'colortablehead0'} width=13\%><font color=$config{'text0'} f +ace=arial size=2><B>Options</B></font></TD></TR>\n"; foreach $file (@allfiles) { $icount++; if($icount > $pagebreak){$icount=1; $pcount++} next if $pcount != $form{page}; $file =~ s/^$config{'basepath'}$form{'category'}\///; $file =~ s/\.dat$//; my ($title, $reserve, $inc, $desc, $image1, $image2, $image3, +$image4, $thumb1, $thumb2, $thumb3, $thumb4, $dutch, $qty, $bold, $hi +ghlight, $feat, $catfeat, $grabber, $relist, $buyit, $gallery, $count +er, $ship1, $ship2, $ship3, $ship4, $ship5, $shipcost, $location, $pa +y1, $pay2, $pay3, $pay4, $pay5, $pay6, $pay7, $pay8, $pay9, $paypal, +$idata1, $idata2, $idata3, $idata4, $idata5, $idata6, $idata7, $idata +8, $idata9, @bids) = &read_item_file($form{'category'},$file); chomp($title, $reserve, $inc, $desc, $image1, $image2, $image3 +, $image4, $thumb1, $thumb2, $thumb3, $thumb4, $dutch, $qty, $bold, $ +highlight, $feat, $catfeat, $grabber, $relist, $buyit, $gallery, $cou +nter, $ship1, $ship2, $ship3, $ship4, $ship5, $shipcost, $location, $ +pay1, $pay2, $pay3, $pay4, $pay5, $pay6, $pay7, $pay8, $pay9, $paypal +, $idata1, $idata2, $idata3, $idata4, $idata5, $idata6, $idata7, $ida +ta8, $idata9, @bids); my @firstbid = split(/\[\]/,$bids[0]); my @lastbid = split(/\[\]/,$bids[$#bids]); my $usersfeed = &feeder($firstbid[0],2); my $usersfeed2 = &feeder2($firstbid[0],2); my $bidderfeed = &feeder($lastbid[0],2); if ($title ne '') { my ($alias, $email, $bid, $time, $add1, $add2, $add3, $oqt +y, $qtysold) = &read_bid($bids[$#bids]); my ($selleralias, $selleremail, $sellerbid, $sellertime, $ +selleradd1, $selleradd2, $selleradd3) = &read_bid($bids[0]); my $timeleft = &timeleft($file); my $imagedisp = "<IMG SRC=$thumb1 BORDER=0>"; my $rowcolor; if ($highlight eq "Yes") { $rowcolor = $config{'yellowrow'}; } else { $rowcolor = $cellcolor[$color]; } if ($alias eq $selleralias){ $bidderfeed = "No bids yet..."; my $lastbid = $sellerbid; } else { $bidderfeed = "$bidderfeed"; } if ($bold eq $config{'bolditemnum'}) { print "<TR><TD align=left BGCOLOR=$rowcolor>"; print "<br><left><table width=80 height=80 bgcolor=000 +000><tr><td align=center><A HREF=$ENV{'SCRIPT_NAME'}\?category=$form{ +'category'}\&item=$file>$imagedisp</a></td></tr></table>" if ($thumb1 +); print "<TD BGCOLOR=$rowcolor><font face=arial size=2> +<A HREF=$ENV{'SCRIPT_NAME'}\?category=$form{'category'}\&item=$file>< +b>$title</b></A></font>"; print " <IMG SRC=$config{'buyiticonsm'}>" if (($buyit > + 0) && ($#bids < 1)); print "</TD><TD align=right BGCOLOR=$rowcolor><font face=a +rial size=2><b>$config{'currency'}$bid</b></font></TD><TD align=cente +r BGCOLOR=$rowcolor><font face=arial size=2>$#bids</font></TD><TD ali +gn=center BGCOLOR=$rowcolor><font face=arial size=2>$bidderfeed</font +></TD><TD BGCOLOR=$rowcolor><font face=arial size=2>$timeleft</font>< +/TD><td BGCOLOR=$rowcolor align=center><A HREF=$ENV{'SCRIPT_NAME'}\?c +ategory=$form{'category'}\&item=$file><img src=\"http://auctionblock. +bidderssite.com/images/viewitembut.png\" border=\"0\"></a><br><br><A +HREF=$ENV{'SCRIPT_NAME'}\?action=trackitem&category=$form{'category'} +&item=$file><img src=\"http://auctionblock.bidderssite.com/images/wat +chbutton.png\" border=\"0\"></a><br><a href=$ENV{'SCRIPT_NAME'}\?acti +on=mailto&category=$form{'category'}&item=$file><img src=\"http://auc +tionblock.bidderssite.com/images/send2friend.png\" border=\"0\"></a>< +/td></TR>\n"; $color = int(!($color)); } else { print "<TR><TD align=left BGCOLOR=$rowcolor>"; print "<br><left><table width=80 height=80 bgcolor=000 +000><tr><td align=center><A HREF=$ENV{'SCRIPT_NAME'}\?category=$form{ +'category'}\&item=$file>$imagedisp</a></td></tr></table>" if ($thumb1 +); print "</TD><TD BGCOLOR=$rowcolor><font face=arial size=2> +<A HREF=$ENV{'SCRIPT_NAME'}\?category=$form{'category'}\&item=$file>$ +title</A></font>"; print " <IMG SRC=$config{'buyiticonsm'}>" if (($buyit > 0) +&& ($#bids < 1)); print "</TD><TD align=right BGCOLOR=$rowcolor><font face=a +rial size=2><b>$config{'currency'}$bid</b></font></TD><TD align=cente +r BGCOLOR=$rowcolor><font face=arial size=2>$#bids</font></TD><TD ali +gn=center BGCOLOR=$rowcolor><font face=arial size=2>$bidderfeed</font +></TD><TD BGCOLOR=$rowcolor><font face=arial size=2>$timeleft</font>< +/TD><td BGCOLOR=$rowcolor align=center><A HREF=$ENV{'SCRIPT_NAME'}\?c +ategory=$form{'category'}\&item=$file><img src=\"http://auctionblock. +bidderssite.com/images/viewitembut.png\" border=\"0\"></a><br><br><A +HREF=$ENV{'SCRIPT_NAME'}\?action=trackitem&category=$form{'category'} +&item=$file><img src=\"http://auctionblock.bidderssite.com/images/wat +chbutton.png\" border=\"0\"></a><br><a href=$ENV{'SCRIPT_NAME'}\?acti +on=mailto&category=$form{'category'}&item=$file><img src=\"http://auc +tionblock.bidderssite.com/images/send2friend.png\" border=\"0\"></a>< +/td></TR>\n"; $color = int(!($color)); } } } print "</TABLE>\n"; print "<font face=arial size=3><div align=center><center><table bo +rder=0 cellpadding=0 cellspacing=0 width=100%><tr><td width=100% bgco +lor=$config{'colortablehead0'} height=3></td></tr></table></center></ +div><br>\n"; pagebreak($pcount,$pagebreak); # This is the bottom pagebrea +k navigation bar print "<BR><BR>\n";




sub pagebreak{ my $begin = "<center>"; my $next = "Next Page >>"; my $nonext = "Next Page >>"; my $previous = "<< Previous Page"; my $noprevious = "<< Previous Page"; my $end = "</center>"; my $urlfragment; foreach(keys %form){ next if($_ eq 'pb' || $_ eq 'page'); my $f = $form{$_}; $f=~s/(\W)/'%'.unpack("H2", $1)/eg; $urlfragment.='&' if $urlfragment; $urlfragment.="$_=$f"; } my($pcount, $pagebreak) = @_; # Print Pagebreak Links print $begin; if($form{page} > 0){ print " <a href=$ENV{SCRIPT_NAME}?$urlfragmen +t&page=@{[$form{page}-1]}&pb=$form{pb}>$previous</a> " } else{ print " $noprevious " } print "|"; for(0..$form{page}-1){ print " <a href=$ENV{'SCRIPT_NAME'}?$urlfra +gment&page=$_&pb=$form{pb}>@{[$_+1]}</a> " } print " <b>", int($form{page})+1, "</b> "; for($form{page}+1..$pcount){ print " <a href=$ENV{'SCRIPT_NAME'}?$ +urlfragment&page=$_&pb=$form{pb}>@{[$_+1]}</a> " } if($pcount>0){ print " <a href=$ENV{'SCRIPT_NAME'}?$urlfragment&pb +=@{[(1+$pcount)*$pagebreak]}>All</a> " } print "|"; if($form{page} < $pcount){ print " <a href=$ENV{'SCRIPT_NAME'}?$ur +lfragment&page=@{[$form{page}+1]}&pb=$form{pb}>$next</a> " } else{ print " $nonext " } print $end; }

Comment on Showing Pagebreak Navigation on top and bottom of pages before foreceach statement?
Select or Download Code
Re: Showing Pagebreak Navigation on top and bottom of pages before foreceach statement?
by Corion (Pope) on Aug 05, 2011 at 07:54 UTC

    All that HTML makes it very hard to get a look at the logic that seems to be wrong in your case. Please either edit your original node or reply with the cleaned up code, where you remove all the unnecessary HTML and replace it by some placeholder. That way, the logic of your program will be far easier to see, for both yourself and us.</op>

Re: Showing Pagebreak Navigation on top and bottom of pages before foreceach statement?
by duyet (Scribe) on Aug 05, 2011 at 09:03 UTC

    Agreed with Corion regards to all that HTML. Maybe you want to look into Template-toolkit to separate your code and HTML.

    pagebreak($pcount,$pagebreak) is where the the navigation is created, but is not here. The problem is in there. Maybe you can post it.

    Also you might want to look at your HTML, it's full with errors and warnings.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://918678]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (13)
As of 2014-09-22 20:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (198 votes), past polls