【发布时间】:2019-05-06 08:59:10
【问题描述】:
我有一个用于调查的表格。问题在一张表中,可能的回答(pr)在另一张表中。当一个响应被赋予一个 pr 字段时,pr_count 将加一。
问题是,在表单输入行上,我尝试了不同的方法来获取数组。
目前我得到的数组是:
survey => 1
1 => 3
2 => 4
submitted => submitted
confirm => Submit Survey
我只需要1=>3 和2=>4 那将是问题1 答案是pr_id 3 完美!我如何在没有调查、提交和确认的情况下得到这个? `
echo '<form method="post"action="/survey1">';
echo '<input type="hidden" name="survey" value="'.$survey.'">';
while ($i <= $qcount){
//query gets questions for a particular survey
$stmt = $link->prepare('SELECT question_num, survey_question.question_text as question, survey_question.question_id
FROM survey_question
WHERE survey_id = ?
AND question_num = ?
ORDER BY survey_question.question_num');
$stmt->execute(array($survey, $i));
while ($row = $stmt->fetch()) {
echo $row['question'] . "<br>";
//query gets possible responses
$stmt2 = $link->prepare('SELECT question_num, pr_num, survey_question.question_id, survey_pr.pr_text as possible, pr_id
FROM survey_question, survey_pr
WHERE survey_id = ?
AND question_num = ?
AND survey_question.question_id = survey_pr.question_id
ORDER BY survey_question.question_num, pr_id');
$stmt2->execute(array($survey, $i));
while ($row2 = $stmt2->fetch()) {
$qid = $row2['question_id'];
$prid= $row2['pr_id'];
echo '<input type="radio" name="'.$qid.'" value="'. $prid .'">'.$row2['possible'].'<br> ';
}
}
$i++;
}
echo '<input type="hidden" name="submitted" value="submitted"/>';
echo '<input name="confirm" type="submit" class="button" value="Submit Survey"/>';
【问题讨论】:
-
echo ''.$row2['possible'].'';
-
试图更好地解释这一点表单提出了可能回答的问题,而循环显示下一个可能回答的问题。我需要 if 语句的提交值。并且提交是显而易见的。我从来没有不只是通过单选按钮命名的东西。
-
抱歉,代码示例让您的问题更加模糊。您的查询是否为
submitted、confirm等返回一行? -
旁注:你确实有一个结束
</form>标签,对吧?
标签: php database forms dynamic radio