gpt4 book ai didi

php - 需要稍微改变表格的布局

转载 作者:行者123 更新时间:2023-11-30 23:26:17 25 4
gpt4 key购买 nike

我有一个关于如何在我的 php 代码中显示正确布局的问题:

好的,我想在表格中显示单个评估中的所有问题。现在显示如下:

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)
  1. 正如您从新显示中看到的那样。我希望属于一个问题的每个答案都显示在它们自己的行中,而不是它目前正在做的一行中的所有答案。
  2. 我遇到的另一个问题是每个问题只显示一个文本输入。它应该为问题中的每个答案显示文本输入。

我的问题是第1点和第2点如何实现才能匹配新布局?

下面是当前显示的代码:

$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>

最佳答案

什么是 E、C 和 B?它们是问题 2 的答案吗?如果是这样,我假设 $searchAnswer 包含它们(E、C、B)。所以我认为您应该为此使用 foreach 循环。

foreach($searchAnswer as $key){
echo "$key<br />";
}

for($i=0;$i<count($searchAnswer);$i++){
echo "$searchAnswer[$i]<br />";
}

祝你好运。

关于php - 需要稍微改变表格的布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13196583/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com