以下是演示DEMO
在演示中,选择评估,提交评估,然后当出现学生和问题下拉菜单时,单击其他提交按钮。您将看到一个未定义的变量出现。我想要做的是回复Assessment
下拉菜单中的评估名称,数据和时间。但是怎么做呢?
以下是相关代码:
function PickSession()
{
//ASSESSMENT DROP DOWN MENU:
//Get data from database
$sessionquery = "
SELECT s.SessionId, SessionName, SessionDate, SessionTime, SessionActive, Complete
FROM Session s
INNER JOIN Session_Complete sc ON sc.SessionId = s.SessionId
WHERE
(Complete = ?)
ORDER BY SessionName
";
$complete = 1;
global $mysqli;
$sessionqrystmt=$mysqli->prepare($sessionquery);
// You only need to call bind_param once
$sessionqrystmt->bind_param("i",$complete);//it doesn't recognse $userid
// get result and assign variables (prefix with db)
$sessionqrystmt->execute();
$sessionqrystmt->bind_result($dbSessionId,$dbSessionName,$dbSessionDate,$dbSessionTime, $dbSessionActive, $dbComplete);
$sessionqrystmt->store_result();
?>
<form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
<p>
<strong>Asessments:</strong>
<select name="session" id="sessionsDrop">
<option value="">Please Select</option>
<?php
while ( $sessionqrystmt->fetch() ) {
$sv = $dbSessionId;
if(isset($_POST["session"]) && $sv == $_POST["session"])
echo "<option selected='selected' value='$sv'>" . $dbSessionName . " - " . date('d-m-Y',strtotime($dbSessionDate)) . " - " . date('H:i',strtotime($dbSessionTime)) . "</option>" . PHP_EOL;
else
echo "<option value='$sv'>" . $dbSessionName . " - " . date('d-m-Y',strtotime($dbSessionDate)) . " - " . date('H:i',strtotime($dbSessionTime)) . "</option>" . PHP_EOL;
}
?>
</select>
</p>
<input id="sessionSubmit" type="submit" value="Submit Assessments" name="sessionSubmit" />
</form>
<?php
}
--------------------------------------------------------------------
function SessionIsSubmitted()
{
if(isset($_POST["session"]) && empty($_POST["session"])) // We picked the "Please select" option
{ ?>
Please Select an Assessment
<?php
return false;
}
else if(!isset($_POST["session"]))
{
return false;
}
else // All is ok
{
return true;
}
return false;
}
--------------------------------------------------------------------
function ShowAssessment()
{
//STUDENT AND QUESTION DROP DOWN MENU GO HERE
//button - name='answerSubmit' goes here
}
--------------------------------------------------------------------
function StudentAnswersIsSubmitted()
{
if(!isset($_POST["answerSubmit"]))
{
return false;
}
else // All is ok
{
return true;
}
return false;
}
--------------------------------------------------------------------
function StudentAnswers()
{
echo $dbSessionName . " - " . $dbSessionDate . " " . $dbSessionTime;
}
?>
Below is functions structure:
<?php
PickSession(); // Show the thing to pick session
if(SessionIsSubmitted()) // When session is picked
{
ShowAssessment(); // Show students and questions information
if(StudentAnswersIsSubmitted()) // Student Answers button is submitted
{
StudentAnswers();
}
}
?>
答案 0 :(得分:0)
您不能通过放置数组变量$dbSessionName
来打印一个选定的元素。所有评估都存储在此数组中,您希望通过放置数组变量来打印所选的评估。尝试仅打印已选择的数组元素。
这样做:
<select name="session[]" id="sessionsDrop">
if (isset($_POST['Submit']) == 1) {
$session_name = $_POST['session'];
echo $session;
}