Hi everyone im newbie here..
can anyone help me to solve this problem. i have a problem with this code i create a function that get the value of dynamic radio button ,,please check my code.
><?php
global $conn;
$a= array();
$conn->cursorlocation = 3;
$query = "SELECT * FROM tbquestion";
$rs = $conn->execute($query);
if (!$rs)
echo "fdsaf";
else {
$num_columns = $rs->Fields->Count();
$n=1;
while (!$rs->EOF)
{
//$num = $rs->fields['QuestionID'];
$numID = $rs->fields['id'];
$num1 = $rs->fields['Question'];
$a[$n] = $rs->fields['a'];
$b[$n] = $rs->fields['b'];
$c[$n]= $rs->fields['c'];
echo "$n.";
//echo $num;
echo " ";
echo $num1;
echo "<br>";
echo " ";
echo "<input name='$a[$n]' type='radio' value='$a[$n]'>$a[$n]";
echo " ";
echo "<input name='$a[$n]' type='radio' value='$b[$n]'>$b[$n]";
echo " ";
echo "<input name='$a[$n]' type='radio' value='$c[$n]'>$c[$n]";
echo " ";
echo "<br>";
echo "<br>";
$n=$n + 1;
$rs->MoveNext(); //move on to the next record
}
$rs->Close();
$rs = null;
function checks(){
global $a;
global $n;
global $conn;
$conn->cursorlocation = 3;
$querys = "SELECT * FROM tbquestion";
$rs1 = $conn->execute($querys);
$num_columns1 = $rs1->Fields->Count();
$n=1;
while (!$rs1->EOF)
{
$ans = $rs1->fields['answer'];
$selected_radio=$_POST['$a[$n]'];
if (($selected_radio)==$ans)
{
$n1=$n1+1;
}
$n2=$n2+1;
$rs1->MoveNext(); //move on to the next record
}
echo "Your Score is " . $n1;
}
if (isset($_POST['Submit'])){
checks();
}
}
?>