/    Sign up×
Community /Pin to ProfileBookmark

Problem in printing form variable

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>&nbsp;&nbsp;$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>
“;
} [/code]

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[/code]

appreciate your help.
Thanks
M

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@themoonauthorAug 08.2011 — Anyone !
Copy linkTweet thisAlerts:
@NogDogAug 08.2011 — I think you want to put the part where you echo the $_POST value outside of the while() loop, as where it is now it will be output for every choice returned by that inner query.
×

Success!

Help @themoon spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...