Hi Perrin,
I modified my add_item subroutine to incorporate the arrays. Can you see if I'm on the right track?
I believe that I'm way off base. Especially when it comes to the quantity field. Quantity is a parameter that is being passed. It's not in the database table so I don't know how to incorporate that into the array.
sub add_item
{
my @item_ref;
my @cart_ref;
my ($dbh, $cart_ref, $item_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->{$item_id}))
{
my $sth = $dbh->prepare ("SELECT item_id, description, categor
+y, price, picture, thumbnail, mime_type, color FROM catalog_pet
WHERE item_id = ?");
$sth->execute ($item_id);
my $item_ref = $sth->fetchrow_arrayref ();
$sth->finish ();
return if !defined ($item_ref); # this shouldn't happen...
@cart_ref->[0] = {}; # create new entry, indexed by item ID
@cart_ref->[1] = $item_ref->{description};
@cart_ref->[3] = $item_ref->{price};
@cart_ref->[8] = 1;
}
@cart_ref->[8] = $qty;
@cart_ref->[7] = $color;
push (@cart_ref, @item_ref);
}
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.