Re: Problem Printing Results using while loop
I see you have found a way to solve your problem, but it involves making several queries which probably adds significantly to the processing time. Another way would be to establish a control variable for the question. Then you can tell when the question changes and only print it then, once for each question. Here's your original code with a variable named $control. I left out the db calls.
my $control = '';
# Print form header.
print qq(<form action="pollanswer.cgi" method="POST">);
while (my($id,$identifier,$instructions,$question,$type,$islast,$ansid,$ansident,$ansas) = $sth->fetchrow_array) {
if ($control ne $question ) {
# Display each question.
print qq(<p><b><small>$id. $question</small></b> );
$control = $question;
}
# Display select header.
if ($type eq "select") {
print qq(<br> <select name="answer">);
}
if ($type eq "radio") {
print qq(<br> <input type="radio" name="answer" value="$ansas"><small>$ansas</small></input>);
}
if ($type eq "checkbox") {
print qq(<br> <input type="checkbox" name="answer" value="$ansas"><small>$ansas</small></input>);
}
if ($type eq "select") {
print qq(<option value="$ansas"><small>$ansas</small></option>);
}
# Display select footer.
if ($type eq "select") {
print qq(</select>);
}
}
Subject
Written By
Posted
February 28, 2008 08:07AM
Re: Problem Printing Results using while loop
April 28, 2008 02:35PM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.