Php 我得到一个空白的动态html表
我试图创建动态html表,但问题是它没有显示表中的任何数据。我知道查询是正确的,因为我用sql测试了查询,它输出了数据。我猜我遇到的问题是动态html表本身。代码如下: JavaScript/JQuery: 问题表:(存储每次考试的问题) 答案表:(存储每次考试中每个问题的答案) 个人答案表:(存储每个答案的每个标记) 更新: 看看我的html代码,为什么它会显示如下表: 将Php 我得到一个空白的动态html表,php,jquery,html,mysql,Php,Jquery,Html,Mysql,我试图创建动态html表,但问题是它没有显示表中的任何数据。我知道查询是正确的,因为我用sql测试了查询,它输出了数据。我猜我遇到的问题是动态html表本身。代码如下: JavaScript/JQuery: 问题表:(存储每次考试的问题) 答案表:(存储每次考试中每个问题的答案) 个人答案表:(存储每个答案的每个标记) 更新: 看看我的html代码,为什么它会显示如下表: 将放置在foreach循环外部 foreach($searchQuestionId as $key=>$questi
放置在foreach循环外部
foreach($searchQuestionId as $key=>$questionId){
?>
<tbody>
foreach($searchQuestionId为$key=>$questionId){
?>
到
....
....
foreach($searchQuestionId为$key=>$questionId){
?>
除非此处没有显示某些代码,否则可能是因为$assessment变量没有设置,所以没有向查询发送任何内容
另外,为了确认您确实获得了结果并将其绑定好,我将对searchQuestionContent等数组进行var_转储,以确保它们包含您期望的内容,如果您不知道您的问题在查询/绑定数据中。如果它们确实包含您期望的内容,则您知道问题在于table输出。检查是否缺少php打开标记
我想说,我没有收到任何php错误,因为错误报告已打开,错误控制台中没有错误。我将tbody放置在foreach循环之外,仍然显示空表。如果您是正确的,现在已经输出了内容。我已经标记了您的答案。我可以问一下吗kly问你一个额外的问题。我在上面的问题中包括了一个更新,我能问一下为什么表看起来像它在更新中所做的,而不是它在我所说的屏幕截图中应该是什么样子吗?你需要检查你的标记。我建议你问一个单独的问题,否则它会稀释这个问题的本质设置$assessment变量。我将对每个数组执行var_dump,看看会发生什么,并让您知道var_dump()似乎很好,因为它显示的是array(4){[0]=>int(1)[1]=>int(1)[2]=>int(1)[3]=>int(2)}array(4){[0]=>string(28)“命名ROM中的三个特性”[1]=>string(28)“命名ROM中的三个特性”[2]=>string(28)“列出ROM中的三个特性”[3]=>string(23)”这里是一个单一答案“}数组(4){[0]=>string(1)“a”[1]=>string(1)“B”[2]=>string(1)“D”[3]=>string(4)“True”}数组(4){[0]=>int(5)[1]=>int(5)[3]=>int(5)
,那么你知道这还意味着什么吗?
<?php
if (isset($_POST['id'])) {
$_SESSION['id'] = $_POST['id'];
}
$assessment = $_SESSION['id'];
include('connect.php');
$query = "SELECT q.SessionId, s.SessionName, q.QuestionId, q.QuestionContent, an.Answer, q.QuestionMarks
FROM Session s
INNER JOIN Question q ON s.SessionId = q.SessionId
JOIN Answer an ON q.QuestionId = an.QuestionId AND an.SessionId = q.SessionId
WHERE s.SessionName = ?
ORDER BY q.QuestionId, an.Answer";
// prepare query
$stmt=$mysqli->prepare($query);
// You only need to call bind_param once
$stmt->bind_param("s", $assessment);
// execute query
$stmt->execute();
// This will hold the search results
$searchQuestionId = array();
$searchQuestionContent = array();
$searchAnswer = array();
$searchMarks = array();
// Fetch the results into an array
// get result and assign variables (prefix with db)
$stmt->bind_result($dbSessionId, $dbSessionName, $dbQuestionId, $dbQuestionContent, $dbAnswer, $dbQuestionMarks);
while ($stmt->fetch()) {
$searchQuestionId[] = $dbQuestionId;
$searchQuestionContent[] = $dbQuestionContent;
$searchAnswer[] = $dbAnswer;
$searchMarks[] = $dbQuestionMarks;
}?>
<form id="Marks" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
<table border='1' id='markstbl'>
<thead>
<tr>
<th class='questionth'>Question No.</th>
<th class='questionth'>Question</th>
<th class='answerth'>Answer</th>
<th class='answermarksth'>Marks per Answer</th>
<th class='noofmarksth'>Total Marks</th>
</tr>
</thead>
<?php
$row_span = array_count_values($searchQuestionId);
$prev_ques = '';
foreach($searchQuestionId as $key=>$questionId){?>
<tbody>
<tr class="questiontd">
<?php
if($questionId != $prev_ques){?>
<td class="questionnumtd" name="numQuestion" rowspan="<?=$row_span[$questionId]?>"><?=$questionId?> <input type="hidden" name="q<?=$questionId?>_ans_org" class="q<?=$questionId?>_ans_org" value="<?=$searchMarks[$key]?>"><input type="hidden" name="q<?=$questionId?>_ans" class="q<?=$questionId?>_ans" value="<?=$searchMarks[$key]?>"></td>
<td class="questioncontenttd" rowspan="<?=$row_span[$questionId]?>"><?=$searchQuestionContent[$key]?> </td>
<?php
}else{?>
<td class="questionnumtd" name="numQuestion" ></td>
<td class="questioncontenttd" ></td>
<?php
}?>
<td class="answertd" name="answers[]"><?=$searchAnswer[$key]?></td>
<td class="answermarkstd">
<input class="individualMarks q<?=$questionId?>_mark_0" q_group="1" name="answerMarks[]" id="individualtext" type="text" />
</td>
<?php
if($questionId != $prev_ques){?>
<td class="noofmarkstd q<?=$questionId?>_ans_text" q_group="1" rowspan="<?=$row_span[$questionId]?>"><?=$searchMarks[$key]?></td>
<?php
}else{?>
<td class="noofmarkstd" q_group="1"></td>
<?php
}?>
</tr>
<?php
$prev_ques = $questionId;
}?>
</tbody>
</table>
</form>
SessionId SessionName
1 AAA
SessionId QuestionId QuestionContent Total Marks
1 1 Name three features in a ROM 5
1 2 Here is a single answer 5
AnswerId(auto) SessionId QuestionId Answer
1 1 1 A
2 1 1 B
3 1 1 D
4 1 2 True
AnswerId AnswerMarks
1 2
2 2
3 1
4 5
foreach($searchQuestionId as $key=>$questionId){
?>
<tbody>
</thead>
<tbody>
....
....
foreach($searchQuestionId as $key=>$questionId){
?>