Hi, I have a web form with a series of questions with multiple choices retrieved from a DB.
My form looks like the following:
[code=php]$sql = “SELECT *
FROM questions
WHERE TypeID = ‘2’
AND ActiveID = ‘1’
Order By Sort_Id,QuestionID
“;
$query = mssql_query($sql) or die(“Problem with SQL:<br/> $sql”);
while ($row = mssql_fetch_array($query)) {
$ArQuestion = $row[‘ArQuestion’];
$Question = $row[‘Question’];
$QuestionID = $row[‘QuestionID’];
$KPIID = $row[‘KPIID’];
$TypeID = $row[‘TypeID’];
$ActiveID = $row[‘ActiveID’];
$Input_Type_Id = $row[‘Input_Type_Id’];
$sql_IN = “SELECT *
FROM choices
WHERE QuestionID = ‘$QuestionID’
“;
$query_IN = mssql_query($sql_IN) or die(“Problem with SQL:<br/> $sql_IN”);
echo ”
<tr>
<td class=”somesmall”><b></b> $Question? ($Input_Type_Id) </td>
<td class=”somesmall” rowspan=2>
<table cellspacing=0 cellpadding=1 border=0>”;
while ($row_in = mssql_fetch_array($query_IN)) {
$ChoicesID = $row_in[‘ChoicesID’];
$QuestionID_in = $row_in[‘QuestionID’];
$Choices = $row_in[‘Choices’];
$ChoicesValue = $row_in[‘ChoicesValue’];
echo ”
<tr>
<td class=”somesmall”><input type=”radio” name=”que$QuestionID_in” value=”$ChoicesID”>$Choices</td>
</tr>
“;
}
echo ”
</table>
</td>
</tr>
“;
}
My problem is how can i just print the value of the form variables without repeating so that i can insert them to the DB.
i tried to print it this way, but it is duplicating the choices.
[code=php]$sql = “SELECT *
FROM questions
WHERE TypeID = ‘2’
AND ActiveID = ‘1’
Order By Sort_Id,QuestionID
“;
$query = mssql_query($sql) or die(“Problem with SQL:<br/> $sql”);
$count =0;
while ($row = mssql_fetch_array($query)) {
$count ++;
$QuestionID = $row[‘QuestionID’];
$Input_Type_Id = $row[‘Input_Type_Id’];
$sql_IN = “SELECT *
FROM choices
WHERE QuestionID = ‘$QuestionID’
“;
$query_IN = mssql_query($sql_IN) or die(“Problem with SQL:<br/> $sql_IN”);
if ($Input_Type_Id==1) {
$count = 0;
while ($row_in = mssql_fetch_array($query_IN)) {
$count ++;
$ChoicesID = $row_in[‘ChoicesID’];
$QuestionID_in = $row_in[‘QuestionID’];
$Choices = $row_in[‘Choices’];
$ChoicesValue = $row_in[‘ChoicesValue’];
//echo “name=”que$QuestionID_in” value=”$ChoicesID”>$Choices</td>”;
if (!empty($_POST[“que$QuestionID_in”])) {
echo $_POST[“que$QuestionID_in”].”<br/>”;
}
}
} //close inner while
} //close the first while
appreciate your help.
Thanks
M