我有一个应用程序,您可以在此处查看以测试应用程序,但我遇到了一些我似乎无法弄清楚的小问题。
即使查询是正确的,它也无法显示在下面的代码中选择的模块:
<p> <strong>Selected Module:</strong><?php $dbModuleNo;?> - <?php$dbModuleName;?> <input type='hidden' value='<?php$_POST["module"];?>'> </p>
只有在用户从相关下拉菜单之一中选择一个选项并提交后,我才能显示
Please Select Module
和消息:Please Select an Assessment
Please Select
代码如下(我注释掉了查询):
<form action="" method="post">
<?php
/*
$moduleactive = 1;
$sql = "SELECT ModuleId, ModuleNo, ModuleName FROM Module WHERE ModuleActive = ? ORDER BY ModuleNo";
$sqlstmt=$mysqli->prepare($sql);
$sqlstmt->bind_param("i", $moduleactive);
$sqlstmt->execute();
$sqlstmt->bind_result($dbModuleId,$dbModuleNo,$dbModuleName);
$sqlstmt->store_result();
$sqlnum = $sqlstmt->num_rows();
*/
?>
Module:
<select name="module" id="modulesDrop">
<option value="">Please Select</option>
<?php
while($sqlstmt->fetch()) {
$ov = $dbModuleNo . "_" . $dbModuleName . "_" . $dbModuleId;
if($ov == $_POST["module"])
echo "<option selected='true' value='$ov'>$dbModuleNo - $dbModuleName</option>" . PHP_EOL;
else
echo "<option value='$ov'>$dbModuleNo - $dbModuleName</option>" . PHP_EOL;
}
?>
</select>
<input id="moduleSubmit" type="submit" value="Submit Module" name="moduleSubmit" />
</form>
<?php if(isset($_POST["module"]) && $_POST["module"] != "") { ?>
<form action="" method="post">
<p>
<strong>Selected Module:</strong><?php $dbModuleNo;?> - <?php$dbModuleName;?> <input type='hidden' value='<?php$_POST["module"];?>'>
</p>
Asessments:
<?php
/*
$sessionquery = "
SELECT s.SessionId, SessionName, SessionDate, SessionTime, ModuleId, SessionActive, Complete
FROM Session s
INNER JOIN Session_Complete sc ON sc.SessionId = s.SessionId
WHERE
(ModuleId = ? AND SessionActive = ? AND Complete = ?)
ORDER BY SessionName
";
$active = 1;
$complete = 1;
$sessionqrystmt=$mysqli->prepare($sessionquery);
// You only need to call bind_param once
$sessionqrystmt->bind_param("iii",$moduleId, $active, $complete);
// get result and assign variables (prefix with db)
$sessionqrystmt->execute();
$sessionqrystmt->bind_result($dbSessionId,$dbSessionName,$dbSessionDate,$dbSessionTime, $dbModuleId, $dbSessionActive, $dbComplete);
$sessionqrystmt->store_result();
$sessionnum = $sessionqrystmt->num_rows();
*/
if ($sessionnum == 0 ){ ?>
<span class='red'>Sorry, You have No Assessments under this Module</span>
<?php } else { ?>
<select name="session" id="sessionsDrop">
<option value="">Please Select</option>
<?php
while ( $sessionqrystmt->fetch() ) {
$sv = $dbSessionId;
if($sv == $_POST["session"])
echo "<option selected='true' 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>
<br>
<input type="submit" value="Submit Assigments">
</form>
<br>
<br>
<?php
if(isset($_POST["session"]) && $_POST["session"] != "") {
/*
$sessiondetailsquery = "
SELECT s.SessionId, SessionName, SessionDate, SessionTime, SessionDuration, SessionWeight, TotalMarks,
s.ModuleId, ModuleNo, ModuleName, s.Room, Building, Capacity, SessionActive, Complete, PenaltyEnabled, COUNT(PenaltyMarks)
FROM Module m
INNER JOIN Session s ON m.ModuleId = s.ModuleId
INNER JOIN Session_Complete sc ON sc.SessionId = s.SessionId
LEFT JOIN Room r ON s.Room = r.Room
LEFT JOIN Penalty p ON s.SessionId = p.SessionId
LEFT JOIN Penalty_Marks pm ON s.SessionId = pm.SessionId
WHERE
(s.SessionId = ?)";
$active = 1;
$complete = 1;
$sessiondetailsqrystmt=$mysqli->prepare($sessiondetailsquery);
// You only need to call bind_param once
$sessiondetailsqrystmt->bind_param("i",$dbSessionId);
// get result and assign variables (prefix with db)
$sessiondetailsqrystmt->execute();
$sessiondetailsqrystmt->bind_result($detailsSessionId,$detailsSessionName,$detailsSessionDate,$detailsSessionTime, $detailsSessionDuration, $detailsSessionWeight,
$detailsTotalMarks, $detailsModuleId, $detailsModuleNo, $detailsModuleName, $detailsRoom, $detailsBuilding, $dbCapacity, $detailsSessionActive, $detailsComplete,
$dbPenaltyEnabled, $dbCountPenalyMarks);?>
*/
<h3>CHOSEN ASSESSMENT</h3>
<input type='text' id='currentId' name='Idcurrent' readonly='readonly' value='$detailsSessionId' /></td>
<br>
<strong>Assessment:</strong> <?php $detailsSessionName; ?>
<?php } else { ?>
<p><strong class='red'>Please Select an Assessment</strong></p>
<?php } } } else { ?>
<p><strong class='red'>Please Select a Module</strong></p>
<?php } ?>