2012-11-02 33 views
1

的布局略有变化我如何在我的PHP代码显示正确的布局上的问题:需求表

OK我要显示所有的问题在一个表中的单个评估。现在,此刻它显示如下:

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> 
+0

你的表的代码在哪里? –

+0

它是代码的底部,所有的回声是 – CMB

+0

哦对不起,没有看到它滚动 –

回答

0

什么是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 />"; 
} 

好运。

+0

是的欧洲央行是问题2的答案,我会测试它,看看会发生什么,并回到你身边。我需要在表格中的“答案”列后包含这个,还是将我已经有的foreach($ searchQuestionContent as $ key => $ question)替换为foreach?谢谢 – CMB

+0

替换'echo' '用htmlspecialchars($ searchAnswer [$键])。' ($ i = 0; $ i “;}回声''''with'echo'' }。'' – Wilf

+0

我在for循环中得到'语法错误,意外的T_FOR' – CMB