sub get_product_table { my $sth = shift; my $dbh = WebDB::connect (); my ($clref, $ref); my @row; my @nav_link; my ($color, @color); while (my $ref = $sth->fetchrow_hashref ()) { $clref = $dbh->prepare ("SELECT color, prod_id FROM ite +m WHERE prod_id = ".$ref->{product_id}); $clref->execute(); while (my ($color, $prod_id) = $clref->fetchrow_hashref +()) { push @{$ref->{color}, $ref->{prod_id}}, ($color->{color +}, $prod_id->{prod_id}); } my $serve_url = sprintf ("serve_image.cgi?product_id=%s;picture", + escape ($ref->{product_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 => "prod_id", -override => 1, -default => escapeHTML($ref->{prod_id})), Tr ({-style=>"font-family: verdana; font-size: 10pt;"}, td (img ({-src => $serve_url, -alt => escapeHTML($ref->{product_id} +)})), td ({-width=>"80", -valign=>"top", -align => "center"}, escapeHTML( + $ref->{prod_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)); }
sub add_item { my ($dbh, $cart_ref, $prod_id, $qty, $color) = @_; # If the item isn't already in the cart, look it up from the datab +ase # and store it in the cart as a new entry with a quantity of zero. if (!exists ($cart_ref->{$prod_id})) { my $sth = $dbh->prepare ("SELECT * FROM catalog_pet, item WHER +E catalog_pet.product_id = item.prod_id AND prod_id = ?"); $sth->execute ($prod_id); my $item_ref = $sth->fetchrow_hashref (); $sth->finish (); return if !defined ($item_ref); # this shouldn't happen... $cart_ref->{$prod_id} = {}; # create new entry, indexed by +item ID $cart_ref->{$prod_id}->{description} = $item_ref->{description +}; $cart_ref->{$prod_id}->{price} = $item_ref->{price}; $cart_ref->{$prod_id}->{qty} = 1; } $cart_ref->{$prod_id}->{qty} = $qty; $cart_ref->{$prod_id}->{color} = $color; }
In reply to Re: Re^5: Joining Tables Problem
by b310
in thread Joining Tables Problem
by b310
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |