This is much better, not only because you do not repeat redundant code, but because you are working on N options, not a finite number, like six. But multiple print statements are icky - learn to avoid them now. One alternative is to let CGI.pm do the hard work for you. Also, where are your opening and closing <table> tags? And why are you exiting at the end of the subroutine?use strict; my @options = ( 'Perfect for me', 'Okay, but my first choice was taken', 'My real name, blame my parents', 'Cowboy Neal', ); for (0..$#options) { print "<tr>\n<td align='left' bgcolor='#8f4141'>\n"; print "<font color='#eabf12' size='2'>\n"; print qq|<input name="in_vote" type="radio" value="option_$_">$opti +ons[$_]</font>\n|; print "</td>\n</tr>\n"; }
Lastly, your database schema is, i am sorry to say, not very good at all. At it's very simplest, you only need three tables (not including tables for user info):
PollIf you wanted to get the taly of votes from poll 42 ... well, i will leave that as an excercise. >:) Working with properly designed database tables requires a lot of dilligent effort. Maybe you should be working on something a tad bit less challenging, like learning CGI.pm and templating solutions, before you jump right into databases.select option.description from option inner join poll on option.poll_id = poll.id order by option.number
jeffa
L-LL-L--L-LL-L--L-LL-L-- -R--R-RR-R--R-RR-R--R-RR B--B--B--B--B--B--B--B-- H---H---H---H---H---H--- (the triplet paradiddle with high-hat)
In reply to (jeffa) Re: Voting script using MySQL and DBI
by jeffa
in thread Voting script using MySQL and DBI
by lagrenouille
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |