[英]How do I add a result from a loop to a $_POST[] array?
Good day all, i am working on an Exam app, i created a foreach loop that will pull all the questions from the database and place it in an h4 tag大家好,我正在开发一个考试应用程序,我创建了一个 foreach 循环,它将从数据库中提取所有问题并将其放置在 h4 标签中
foreach($questions as $key => $question) {
echo "<div class=\"form-group\">";
//html output for the questions
echo "<h4 class='questions'> $question</h4>"."<ol>";//display the questions
what i want to do here it to pass the result of the loop $questions
to a $_POST[]
array eg $question = $_POST['question'];
我想在这里做的是将循环
$questions
的结果传递给$_POST[]
数组,例如$question = $_POST['question'];
i tried doing this:我试过这样做:
foreach($questions as $id => $question) {
echo "<div class=\"form-group\">";
//html output for the questions
$uQuestions = $question;
$uQuestions = $_POST['uQuestions'];
echo "<h4 class='questions'> $question</h4>"."<ol>";//display the questions
i got an error我有一个错误
Notice: Undefined index: uQuestions in C:\xampp\htdocs\app\exam.php on line 86
how do i go about it?我该怎么做?
thanks in advance提前致谢
Seems like you get the assignment wrong.好像你把任务弄错了。 This:
这个:
$_POST['uQuestions'] = $question;
will put $question in $_POST but without a unique identifier.将 $question 放入 $_POST 但没有唯一标识符。 When the loop ends $_POST['uQuestions'] will contains the last $question from the loop.
当循环结束时,$_POST['uQuestions'] 将包含循环中的最后一个 $question。
A solution might be:一个解决方案可能是:
$_POST['uQuestions' . $id] = $question;
than you will put all questions in $POST比您将所有问题都放在 $POST 中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.