create table quiz_questions ( quiz_question_id serial not null primary key, question TEXT ); #### create table quiz_answer( quiz_ansswer_id SERIAL not null primary key, quiz_question_id integer not null references quiz_question(quiz_question_id) on delete cascade, quiz_answer text not null, correct_answer boolean not null default 'false' ); #### | | Handwaving here | use strict; use CGI qw/ :all /; my $cgi = new CGI; # This hash reference contains the parameters for # the question... my $question = fetchRandomQueston(); # # This array contains hash references for the answers my @answers = fetchAnswers($question->{quis_question_id}); | | some handwaving here | print $question->{quiz_question},"\n"; print hidden("quiz_question_id", $queston->{quiz_question_id}),br; # There are better ways.. but I'm doing this way # for clarity my %labels = map { $_ -> {quiz_answer_id} => $_ ->{quiz_answer} } @answers; print radio_group( -name=> 'user_answer_rq', -values=> [ map { $_->{quiz_answer_id} } @answers ], -labels => \%labels, -linebreaks => 'true' ),br; print submit; #### use CGI; my $cgi = new CGI; my $answer_id = $cgi->param('user_answer_rq'); my $question_id = $cgi->param('quiz_question_id'); my $answer=find_answer_in_db($answer_id}; if ( $answer->{correct_answer} ){ | process accordingly } else { | ditto }