in reply to Duplicate items in cart do not appear
You've got several separate things going on here and you need to treat them separately. Putting them all together is obviously not working for you, and I can't read your code.
I think you're asking several questions:
The answer in the first case is to find or make something that uniquely identifies a product. That may be an item id, a product id, or a combination of one id and a color.
The answer in the second case is either to keep a stateful loop or to do two separate queries. I'd probably write code such as this:
sub get_colors_for_item { my ($dbh, item_id) = @_; my $sth = $dbh->prepare( 'SELECT color FROM item WHERE item_id = ? +' ); $sth->execute( $item_id ); my @colors; while( my ($color) = $sth->fetchrow_array()) { push @colors, $color; } return @colors; }
The answer to your third question is to write much smaller subroutines. Separate the database work from the printing. What's important is to build and return a data structure that makes it easy to do the printing.
I think you're getting caught up on a combinatorial explosion of details. Stop and take a deep breath. Then write some really small bits that do one simple thing at a time. Put them together -- not in one giant subroutine, but by calling them from a parent sub.
It may be an artifact of posting here, but the indentation of this code is really hard to read. perltidy can help. By default, it does a really good job of making things much more readable. You might find that your code is more maintainable that way too.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Duplicate items in cart do not appear
by b310 (Scribe) on Feb 23, 2003 at 22:36 UTC |