Hello Monks, I'm trying to modify some code to let me have multiple page listings using a previous page, page 1, page 2, next page feature. So far, I was able to successfully modify the code to show the requested number of hits on a page. And, I do get the correct number of hits. My problem is that the navigation link to show previous page, page 1, page 2, next page is not appearing on the bottom of the page. I am not sure what is wrong. Can someone take a look at my code and give me a hand? The line "print hr(), @nav_link should print the navigation links on the page but it doesn't.
sub page_parameters { my ($dbh, $where, @placeholder) = @_; my ($start_pos, $page_size, $max_rec); my @nav_link; # navigation link array my $limit; # LIMIT clause my @row; # summary table row array my ($stmt, $sth); my $str; my $page; # Get the page control parameters. If they're not present, this i +s # the first time we're running this search. In that case, run a q +uery # to determine the result set size and initialize the page paramet +ers. #@ INIT_PAGE_PARAMS $start_pos = param ("start_pos"); $page_size = param ("page_size"); $max_rec = param ("max_rec"); if (!defined (param ("start_pos"))) { $start_pos = 0; $page_size = 2; # change this to change #hits/page $stmt = "SELECT COUNT(*) FROM catalog_pet $where"; $max_rec = $dbh->selectrow_array ($stmt, undef, @placeholder); if ($max_rec == 0) { print p ("Sorry, no qualifying listings were found."); return; } # put values into environment so gen_nav_link() can find them # (except for start_pos, which isn't constant across links) param (-name => "page_size", -value => $page_size); param (-name => "max_rec", -value => $max_rec); } #@ INIT_PAGE_PARAMS # $start_pos = number of initial records to skip # $page_size = number of records to retrieve $limit = "LIMIT $start_pos, $page_size"; print p ("$max_rec matching listings were found."); $sth = $dbh->prepare ("SELECT * FROM catalog_pet $where $limit"); $sth->execute (@placeholder); #@ BUILD_NAV_LINKS if ($max_rec > $page_size) { #@ PREV_PAGE_LINK if ($start_pos == 0) # first page: no prede +cessor { push (@nav_link, "previous"); } else { push (@nav_link, gen_nav_link ("previous", $start_pos-$pag +e_size)); } #@ PREV_PAGE_LINK for (my $i = 0; $i < $max_rec; $i += $page_size) { my $page_no = int ($i / $page_size) + 1; if ($start_pos == $i) # this is the current + page { push (@nav_link, $page_no); } else { push (@nav_link, gen_nav_link ($page_no, $i)); } } if ($start_pos+$page_size >= $max_rec) # last page: no succ +essor { push (@nav_link, "next"); } else { push (@nav_link, gen_nav_link ("next", $start_pos+$page_si +ze)); } my $table = get_product_table ($sth); $page .= ($table ? $table : p ("No items were found.")); $sth->finish (); return ($page); @nav_link = map { "[$_]\n" } @nav_link; print hr(), @nav_link; } #@ BUILD_NAV_LINKS }
sub gen_nav_link { my ($label, $start_pos) = @_; my @param = # parameters to extract from environment ( # page control parameters "max_rec", "page_size", # search parameters "description" ); my $url; # tell the script to continue the search and which record to start + with $url = url () . "?choice=search;start_pos=$start_pos"; # add other page control and search parameters foreach my $name (@param) { my @val = param ($name); # if a parameter has multiple values, add it multiple times foreach my $val (@val) { $url .= ";$name=" . escape ($val); } } return (a ({-href => $url}, escapeHTML ($label))); }
Thanks for your help.

In reply to Multiple page listings - previous/next feature by b310

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.