Hello Everybody,
I’m just starting out with php and mysql and I have a question. I have a FORM with 20 questions, all radio buttons. Now when users click on the send button, I need to show information based on each answer. Only my php code is so big so I think and hope there is an easier way to do this. This is my example code:
[php]
if ($_POST[‘question1’] == “A”) {
$data = mysql_query(“SELECT Column1 FROM test”) or die(mysql_error());
echo “Here I echo the column data with a mysql_fetch_array”;
}
else if ($_POST[‘question1’] == “B”) {
$data = mysql_query(“SELECT Column2 FROM test”) or die(mysql_error());
echo “Here I echo the column data with a mysql_fetch_array”;
}
else if ($_POST[‘question1’] == “C”) {
$data = mysql_query(“SELECT Column3 FROM test”) or die(mysql_error());
echo “Here I echo the column data with a mysql_fetch_array”;
}
if ($_POST[‘question2’] == “A”) {
$data = mysql_query(“SELECT Column4 FROM test”) or die(mysql_error());
echo “Here I echo the column data with a mysql_fetch_array”;
}
else if ($_POST[‘question2’] == “B”) {
$data = mysql_query(“SELECT Column5 FROM test”) or die(mysql_error());
echo “Here I echo the column data with a mysql_fetch_array”;
}
else if ($_POST[‘question2’] == “C”) {
$data = mysql_query(“SELECT Column6 FROM test”) or die(mysql_error());
echo “Here I echo the column data with a mysql_fetch_array”;
}
[/php]
Etc. So if I have 20 questions, I have 20 x 3 = 60 if statements. Is there an easier/faster way to do this?
Thanks so much for helping me out with this!
Kind regards,
Mark