Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to display answers and text inputs within each row
    primarykey
    data
    text
    <p>I have a question on how to display the correct table layout in my php code:</p> <p>I want to display answers and their text inputs in a table.. Now at the moment it is displayed as below:</p> <pre><code> Question Answer Marks Per Answer What is 2+2 B (text input) Name the 3 hobbits? BCE (text input) </code></pre> <p>I want to change the display of the table so that it looks like this below:</p> <pre><code> Question Answer Marks Per Answer What is 2+2? B (text input) Name the 3 Hobbits? B (text input) C (text input) E (text input) </code></pre> <ol> <li>As you can see from the new display. I want the each answer per question to be displayed in thier own row, not all answers per question in in one row which is what it is doing at moment.</li> <li>I want the text inputs to also be display in its own row, like the answers:</li> </ol> <p>My question is that how can point 1 and 2 be achieved so that it can match the new layout?</p> <p>Below is the code for the current display:</p> <pre><code>$assessment = $_SESSION['id'] . $sessionConcat; include('connect.php'); $query = "SELECT q.QuestionId, q.QuestionContent, GROUP_CONCAT(DISTINCT Answer ORDER BY Answer SEPARATOR '') AS Answer, FROM Question q INNER JOIN Answer an ON q.QuestionId = an.QuestionId WHERE s.SessionName = ? "; // prepare query $stmt=$mysqli-&gt;prepare($query); // You only need to call bind_param once $stmt-&gt;bind_param("s", $assessment); // execute query $stmt-&gt;execute(); // This will hold the search results $searchQuestionId = array(); $searchQuestionContent = array(); $searchAnswer = array(); // Fetch the results into an array // get result and assign variables (prefix with db) $stmt-&gt;bind_result($dbQuestionId, $dbQuestionContent, $dbAnswer); while ($stmt-&gt;fetch()) { $searchQuestionContent[] = $dbQuestionId; $searchQuestionContent[] = $dbQuestionContent; $searchAnswer[] = $dbAnswer; } ?&gt; &lt;/head&gt; &lt;body&gt; &lt;form id="QandA" action="&lt;?php echo htmlentities($_SERVER['PHP_SELF']); ?&gt;" method="post"&gt; &lt;?php echo "&lt;table border='1' id='markstbl'&gt; &lt;tr&gt; &lt;th class='questionth'&gt;Question&lt;/th&gt; &lt;th class='answerth'&gt;Answer&lt;/th&gt; &lt;th class='answermarksth'&gt;Marks per Answer&lt;/th&gt; &lt;/tr&gt;\n"; foreach ($searchQuestionContent as $key=&gt;$question) { echo '&lt;td&gt;'.htmlspecialchars($question).'&lt;/td&gt;' . PHP_EOL; echo '&lt;td class="answertd"&gt;'.htmlspecialchars($searchAnswer).'&lt;/td&gt;' . PHP_EOL; echo '&lt;td class="answermarkstd"&gt;&lt;input class="individualMarks" name="answerMarks[]" id="individualtext" type="text" "/&gt;&lt;/td&gt;' . PHP_EOL; } echo "&lt;/table&gt;" . PHP_EOL; ?&gt; &lt;/form&gt; &lt;/body&gt; </code></pre> <p>Below is what Question Table looks like:</p> <p>Question Table:</p> <pre><code>QuestionId (auto) QuestionContent 1 What is 2+2? 2 Name the 3 hobbits? </code></pre> <p>Answer Table:</p> <pre><code>AnswerId (auto) QuestionId Answer 1 1 B 2 2 B 3 2 C 4 2 E </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload