Everything is passed to the next subroutine....sub get_category_items { my @placeholder; my ($cat_name, $where, $limit, $value); $where = qq( WHERE catalog_pet.item_id = colors.item_id AND category = + ? ); $value = param("cat"); if ($value ne "") { push (@placeholder, $value); } shop_parameters($dbh, $cat_name, $where, @placeholder); }
Finally, this code produces the result....sub shop_parameters { my ($dbh, $cat_name, $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, colors $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 nav_gen_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, colors $where ORDER +BY description $limit"); $sth->execute (@placeholder); $page = get_product_table ($sth); if ($page) { $page = p ({-style=>"font-family: verdana; font-size: 10pt;"}, + "Items in product category:\n" . escapeHTML (@placeholder)) . $page; } else { # if the category is empty, say so and show the category list +again $page .= p ({-style=>"font-family: verdana; font-size: 10pt;"} +, "There are no items in this product category:\n" . escapeHTML (@placeholder)); $page .= get_category_list ($dbh); } #@ 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, nav_gen_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, nav_gen_link ($page_no, $i)); } } if ($start_pos+$page_size >= $max_rec) # last page: no succ +essor { push (@nav_link, "next"); } else { push (@nav_link, nav_gen_link ("next", $start_pos+$page_si +ze)); } @nav_link = map { "[$_]\n" } @nav_link; $sth->finish (); $page .= "@nav_link"; } #@ BUILD_NAV_LINKS return ($page); }
Thanks for any help.....sub get_product_table { my $sth = shift; my @row; my @nav_link; while (my $ref = $sth->fetchrow_hashref ()) { my $serve_url = sprintf ("serve_image.cgi?item_id=%s;picture", es +cape ($ref->{item_id})); # generate a form allowing a quantity of the item to be added # to the cart push (@row, start_form(-method=>'POST', -action=>url()), hidden( -name => "choice", -override => 1, -default => "add" ), hidden( -name => "item_id", -override => 1, -default => escapeHTML($ref->{item_id})), Tr ({-style=>"font-family: verdana; font-size: 10pt;"}, td (img ({-src => $serve_url, -alt => escapeHTML($ref->{item_id})}) +), td ({-width=>"80", -valign=>"top", -align => "center"}, escapeHTML( + $ref->{item_id} )), td ({-width=>"190", -valign=>"top"}, escapeHTML( $ref->{description +} ))), td (" "), Tr ({-style=>"font-family: verdana; font-size: 10pt;"}, td ({-colspan => "3", -align => "right", -style=>"font-weight: 700; + color:blue;"}, "Price: \$", escapeHTML( sprintf( "%.2f", $ref->{pri +ce}))), Tr ({-style=>"font-family: verdana; font-size: 10pt;"}, td ({-colspan => "3", -align => "right"}, "Colors:", popup_menu( -n +ame => "color", -values => $ref->{color}))), Tr ({-style=>"font-family: verdana; font-size: 10pt;"}, td ({-colspan => "3", -align => "right"}, "Quantity:", popup_menu( +-name => "quantity", -values => ["1", "2", "3", "4", "5", "6", "7", " +8", "9"])), td (image_button( -name => "Add Item", -src=>"../images/add.jpg", - +border=>"0" )))), Tr ({-valign=>"top"}, td ({-colspan=>"7", -width=>"100%"}, hr)), end_form() ); } $sth->finish (); return undef unless @row; # no items? return (table ({-border => 0, -align => "center", -style=>"font-fa +mily: verdana; font-size: 10pt;"}, @row)); }
update (broquaint): added <readmore> tag
In reply to Joining Tables Problem by b310
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |