Php 需要稍微改变一下桌子的布局
我有一个关于如何在php代码中显示正确布局的问题: 好的,我想在表格中显示单个评估中的所有问题。现在显示如下:Php 需要稍微改变一下桌子的布局,php,html,mysql,css,Php,Html,Mysql,Css,我有一个关于如何在php代码中显示正确布局的问题: 好的,我想在表格中显示单个评估中的所有问题。现在显示如下: Question No. Question Answer Marks Per Answer Total Marks 1 What is 5+5? B (text input) 3 2 Na
Question No. Question Answer Marks Per Answer Total Marks
1 What is 5+5? B (text input) 3
2 Name three maneuvers you will ECB (text input) 7
undergo in a driving test
我想更改表的显示,使其如下所示:
Question No. Question Answer Marks Per Answer Total Marks
1 What is 5+5? B (text input) 3
2 Name three maneuvers you will E (text input)
undergo in a driving test C (text input) 7
B (text input)
$query = "SELECT q.SessionId, s.SessionName, q.QuestionId, q.QuestionContent, GROUP_CONCAT(DISTINCT Answer SEPARATOR '') AS 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 = ?
GROUP BY an.SessionId, an.QuestionId
";
// 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;
}
?>
</head>
<body>
<form id="QandA" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
<?php
echo "<table border='1' id='markstbl'>
<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>\n";
foreach ($searchQuestionContent as $key=>$question) {
echo '<tr class="questiontd">'.PHP_EOL;
echo '<td class="optiontypetd">'.htmlspecialchars($searchQuestionId[$key]).'</td>' . PHP_EOL;
echo '<td>'.htmlspecialchars($question).'</td>' . PHP_EOL;
echo '<td class="answertd">'.htmlspecialchars($searchAnswer[$key]).'</td>' . PHP_EOL;
echo '<td class="answermarkstd"><input class="individualMarks" name="answerMarks[]" id="individualtext" type="text" "/></td>' . PHP_EOL;
echo '<td class="noofmarkstd">'.htmlspecialchars($searchMarks[$key]).'</td>' . PHP_EOL;
}
echo "</table>" . PHP_EOL;
?>
</form>
</body>
$query=“选择q.SessionId、s.SessionName、q.QuestionId、q.QuestionContent、GROUP_CONCAT(不同的答案分隔符“”)作为答案,q.QuestionMarks
来自会话s
s.SessionId=q.SessionId上的内部连接问题q
将q.QuestionId=an.QuestionId和an.SessionId=q.SessionId上的答案连接起来
其中s.SessionName=?
按an.SessionId、an.QuestionId分组
";
//准备查询
$stmt=$mysqli->prepare($query);
//您只需要调用bind_param一次
$stmt->bind_参数(“s”,$assessment);
//执行查询
$stmt->execute();
//这将保存搜索结果
$searchQuestionId=array();
$searchQuestionContent=array();
$searchAnswer=array();
$searchMarks=array();
//将结果提取到数组中
//获取结果并分配变量(前缀为db)
$stmt->bind_result($dbSessionId、$dbSessionName、$dbQuestionId、$dbQuestionContent、$dbAnswer、$dbQuestionMarks);
而($stmt->fetch()){
$searchQuestionId[]=$dbQuestionId;
$searchQuestionContent[]=$dbQuestionContent;
$searchAnswer[]=$dbAnswer;
$searchMarks[]=$dbQuestionMarks;
}
?>
什么是E、C和B?他们是问题2的答案吗?如果是这样,我假设$searchAnswer包含它们(E、C、B)。所以我认为应该使用foreach循环
foreach($searchAnswer as $key){
echo "$key<br />";
}
foreach($searchAnswer作为$key){
回显“$key
”;
}
或
对于($i=0;$i)您的表格的代码在哪里?这是代码的底部,所有的回音都在那里。哦,很抱歉,没有看到它滚动。ECB是问题2的答案。我将测试它,看看会发生什么,然后返回给您。我需要在“答案”之后包含此内容吗表中的列,还是将我已经拥有的foreach($code>foreach($searchQuestionContent as$key=>$question)
Thanksreplaceecho'.''.
替换为echo'.
($i=0;$iIm在FOR循环中得到一个语法错误,意外的T_FOR
,除了它说意外的T-FOREACH@Wilf,for
引入了一条语句,而不是表达式,因此您不能(afaik)使用
将其与其他文本组合。而是使用单独的echo
命令,一个在循环内,两个在循环外。
for($i=0;$i<count($searchAnswer);$i++){
echo "$searchAnswer[$i]<br />";
}