The stupid question is the question not asked | |
PerlMonks |
input form and MySQL across columnsby Da_Skipper (Initiate) |
on Sep 02, 2012 at 21:41 UTC ( [id://991331]=perlquestion: print w/replies, xml ) | Need Help?? |
Da_Skipper has asked for the wisdom of the Perl Monks concerning the following question:
Question: How to match up input form fields across columns in MySQL database?
Problem is due to form fields must be unique. The MySQL table:
An example of the first input form looked something like below except an actual input field would show up where the word "input" is shown and the name would be the same as the MySQL row name. As you can see the name of each field returned is the same because using code like this while($ref = $sth->fetchrow_hashref()){and $ref->{'name'}where "qty1" "qty2" etc is used for each MySQL table heading which returns a form with identical names for each field <input type="text" name="Shoes" size="2"> 15 <input type="text" name="Shoes" size="2"> 50 and so on for each field as shown below
the problem is each input field name must be unique so I appended each with a digit starting with the number 1 and incremented using ++. the results works fine as below. Again, substitute the word "input" with the MySQL row name and an input field.
and then under each input string I added $newname++;like this <input type="text" name="$newname" size="2"> 15 $newname++; <input type="text" name="$newname" size="2"> 50 Gives a nicely formatted form, each field with a unique name. "name=Shoes1" "name=Shoes2" etc. The probem is, the fields no longer match the name of the row that it came from which causes a problem. I thought about using the row/column value instead of the row name but, there is still the potential of duplicate form field names, so that wouldn't work.
So if the connectivity between the form and the MySQL table worked, (my fault, not perl's) the next bit of code would be to write "if input value is greater than 0, multiply the value by the qty in the MySQL row/column and then add up each subtotal by row. My first attempt returned the input value but stuck the same value into the entire column even when multiple inputs were provided. I think this is because I was using "while fetchrow" again instead of something that parsed for each individual row, not sure. So this is where I am stumped, I've done this before with other forms but, not across multiple columns, only when working with a single row and single column value. I'm thinking the answer is in arrays but I'm having a brain freeze! Any help is appreciated.
Back to
Seekers of Perl Wisdom
|
|