它的输出详细信息在php / html中不正确
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了它的输出详细信息在php / html中不正确,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含6388字,纯文字阅读大概需要10分钟。
内容图文
![它的输出详细信息在php / html中不正确](/upload/InfoBanner/zyjiaocheng/777/e26bddb3a8164925992fd69ae64dc64f.jpg)
当用户从问题下拉菜单中选择全部并在下面输出时,我想从下拉菜单中显示所有问题.问题是,它没有这样做,并使其变得更糟,它给了我未定义的偏移错误说明:
Notice: Undefined offset: ... in .... on line 605
605行是:
echo '<p><strong>Question:</strong> ' .htmlspecialchars($arrQuestionNo[$key]). ': ' .htmlspecialchars($arrQuestionContent[$key]). '</p>' . PHP_EOL;
我的问题是如果用户选择所有选项,如何修复错误并显示所有问题?
我有一个你可以通过的演示:DEMO
按照以下步骤:
>在Module下拉菜单中,选择System Stratergy并提交
>出现评估下拉菜单时,选择POKUB1并提交
>您将看到学生和问题下拉菜单.你可以看到,如果你打开下拉菜单,那里有3个学生和2个问题.请选择一个学生和所有问题和ubmit.在这里您可以看到错误,我想在此处显示所有问题的详细信息.
码:
问题下拉菜单:
<select name="question" id="questionsDrop">
<option value="0">All</option>
<option value=23">1</option>
<option value=32">1</option>
</select>
以下是根据从问题下拉菜单中选择的选项来确定显示的代码.
function StudentAnswers()
{
$selectedstudentanswerqry = "
SELECT
sa.StudentId, StudentAlias, StudentForename, StudentSurname, q.SessionId,
QuestionNo, QuestionContent, o.OptionType, q.NoofAnswers,
GROUP_CONCAT( DISTINCT Answer ORDER BY Answer SEPARATOR ',' ) AS Answer, r.ReplyType, QuestionMarks,
GROUP_CONCAT(DISTINCT StudentAnswer ORDER BY StudentAnswer SEPARATOR ',') AS StudentAnswer, ResponseTime, MouseClick, StudentMark
FROM Student st
INNER JOIN Student_Answer sa ON (st.StudentId = sa.StudentId)
INNER JOIN Student_Response sr ON (sa.StudentId = sr.StudentId)
INNER JOIN Question q ON (sa.QuestionId = q.QuestionId)
INNER JOIN Answer an ON q.QuestionId = an.QuestionId
LEFT JOIN Reply r ON q.ReplyId = r.ReplyId
LEFT JOIN Option_Table o ON q.OptionId = o.OptionId
";
// Initially empty
$where = array('q.SessionId = ?');
$parameters = array($_POST["session"]);
$parameterTypes = 'i';
// Check whether a specific question was selected
$p_question = empty($_POST["question"])?'':$_POST["question"];
switch($p_question){
case 0:
//dont' add where filters
break;
default:
$where[] = 'q.QuestionId = ?';
$parameters[] .= $_POST["question"];
$parameterTypes .= 'i';
}
// If we added to $where in any of the conditionals, we need a WHERE clause in
// our query
if(!empty($where)) {
$selectedstudentanswerqry .= ' WHERE ' . implode(' AND ', $where);
global $mysqli;
$selectedstudentanswerstmt=$mysqli->prepare($selectedstudentanswerqry);
// You only need to call bind_param once
if (count($where) == 1) {
$selectedstudentanswerstmt->bind_param($parameterTypes, $parameters[0]);
}
else if (count($where) == 2) {
$selectedstudentanswerstmt->bind_param($parameterTypes, $parameters[0], $parameters[1]);
}
}
$selectedstudentanswerqry .= "
GROUP BY sa.StudentId, q.QuestionId
ORDER BY StudentAlias, q.SessionId, QuestionNo
";
// get result and assign variables (prefix with db)
$selectedstudentanswerstmt->execute();
$selectedstudentanswerstmt->bind_result($detailsStudentId,$detailsStudentAlias,$detailsStudentForename,$detailsStudentSurname,$detailsSessionId,$detailsQuestionNo,
$detailsQuestionContent,$detailsOptionType,$detailsNoofAnswers,$detailsAnswer,$detailsReplyType,$detailsQuestionMarks,$detailsStudentAnswer,$detailsResponseTime,
$detailsMouseClick,$detailsStudentMark);
$selectedstudentanswerstmt->store_result();
$selectedstudentanswernum = $selectedstudentanswerstmt->num_rows();
$question = array();
while ($selectedstudentanswerstmt->fetch()) {
$arrQuestionNo = array();
$arrQuestionContent = array();
$arrQuestionNo[ $detailsStudentId ] = $detailsQuestionNo;
$arrQuestionContent[ $detailsStudentId ] = $detailsQuestionContent;
$questions[] = $arrQuestionNo;
$questions[] = $arrQuestionContent;
}
$selectedstudentanswerstmt->close();
?>
...........................................................................................
<h2>STUDENT'S ANSWERS</h2>
<?php
foreach ($questions as $key=>$question) {
echo '<p><strong>Question:</strong> ' .htmlspecialchars($arrQuestionNo[$key]). ': ' .htmlspecialchars($arrQuestionContent[$key]). '</p>' . PHP_EOL;
}
}
?>
更新:
学生表结构:
CREATE TABLE `Student` (
`StudentId` int(10) NOT NULL AUTO_INCREMENT,
`StudentForename` varchar(25) NOT NULL,
`StudentSurname` varchar(25) NOT NULL,
`StudentAlias` varchar(15) NOT NULL,
`StudentEmail` varchar(50) NOT NULL,
`StudentUsername` varchar(20) NOT NULL,
`StudentPassword` varchar(50) NOT NULL,
`StudentDOB` date NOT NULL,
`Year` int(2) NOT NULL,
`CourseId` int(6) NOT NULL,
`Active` tinyint(1) NOT NULL DEFAULT '1',
PRIMARY KEY (`StudentId`),
KEY `FK_Course` (`CourseId`)
) ENGINE=InnoDB AUTO_INCREMENT=41 DEFAULT CHARSET=utf8
问题表结构:
CREATE TABLE `Question` (
`QuestionId` int(10) NOT NULL AUTO_INCREMENT,
`SessionId` int(10) NOT NULL,
`QuestionNo` int(3) NOT NULL,
`QuestionContent` varchar(5000) NOT NULL,
`NoofAnswers` int(2) NOT NULL,
`ReplyId` int(1) NOT NULL,
`QuestionMarks` int(4) NOT NULL,
`OptionId` int(2) NOT NULL,
PRIMARY KEY (`QuestionId`)
) ENGINE=InnoDB AUTO_INCREMENT=357 DEFAULT CHARSET=utf8
解决方法:
试一试…….
$question = array();
while ($selectedstudentanswerstmt->fetch()) {
// assuming you don't need the StudentId
$questions[] = array('no' => $detailsQuestionNo,
'content' => $detailsQuestionContent);
}
和
foreach ($questions as $key => $question) {
echo '<p><strong>Question:</strong> ' .
htmlspecialchars($question['no']) .
': ' .
htmlspecialchars($question['content']) .
'</p>' .
PHP_EOL;
}
EDITED
或者,如果您按问题分组,可以试试这个:
$question = array();
while ($selectedstudentanswerstmt->fetch()) {
if (true === isset($questions[$detailsQuestionId])) {
$questions[$detailsQuestionId]['students'][] = $detailsStudentId;
} else {
$questions[$detailsQuestionId] = array();
$questions[$detailsQuestionId]['no'] = $arrQuestionNo;
$questions[$detailsQuestionId]['content'] = $arrQuestionContent;
$questions[$detailsQuestionId]['students'] = array();
$questions[$detailsQuestionId]['students'][] = $detailsStudentId;
}
}
foreach ($questions as $questionId => $question) {
// $question['no']
// $question['content']
foreach($question['students'] AS $key => $studentId) {
// $studentId
}
}
或者,如果您按用户ID分组…
$students = array();
while ($selectedstudentanswerstmt->fetch()) {
if (false === isset($students[$detailsStudentId])) {
$students[$detailsStudentId] = array();
}
$students[$detailsStudentId][$detailsQuestionId] =
array('no' => $arrQuestionNo,
'content' => $arrQuestionContent;
}
foreach ($students AS $studentId => $questions) {
// $studentId
foreach ($questions AS $questionId => $question) {
// $questionId
// $question['no']
// $question['content']
}
}
内容总结
以上是互联网集市为您收集整理的它的输出详细信息在php / html中不正确全部内容,希望文章能够帮你解决它的输出详细信息在php / html中不正确所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。