XP is just a number | |
PerlMonks |
Re: Recalculating DB valuesby jwest (Friar) |
on Jul 03, 2001 at 02:15 UTC ( [id://93340]=note: print w/replies, xml ) | Need Help?? |
As always, there is more than one way to do it. I'd probably
go about it like this: First, when generating the fields for the add and subtract columns, give them predictable names. Perhaps 'add_productid' and 'subtract_productid' where productid is the same as the identifier you use in your database, probably the primary key. Then, get the parameters passed in to your script. If your CGI query object is $q, you can do this with a call like my %params = $q->Vars; Then, loop through the keys of %params, searching for keys that match the names you are expecting. So, if you encounter a key for 'add_1', and you're willing to update the quantity of the product with the identifier of '1' (not that you should be using numbers as hash keys as I have below, strictly speaking), you can set the quantity using the value of that parameter. The same holds true with 'subtract'. This would give you a piece of code that looks a little like:
Of course, this lacks details specific to your project (such as manipulating your database). It's also untested, and probably a sub-optimal solution. But it should start you in the right direction. Hope this helps! --jwest -><- -><- -><- -><- -><- All things are Perfect To every last Flaw And bound in accord With Eris's Law - HBT; The Book of Advice, 1:7
In Section
Seekers of Perl Wisdom
|
|