我想将变量存储到我的 mysqli:fetch() 语句的 while 循环中,问题是我认为我编写的代码不正确。特别是对于变量$dataArraySession
,任何人都可以查看下面的代码并说明编写下面代码的正确方法是什么:
$sessionquery = "
SELECT SessionId, SessionDate, SessionTime, ModuleId
FROM Session
WHERE
(ModuleId = ?)
ORDER BY SessionDate, SessionTime
";
$sessionqrystmt=$mysqli->prepare($sessionquery);
// You only need to call bind_param once
$sessionqrystmt->bind_param("s",$_POST['modulesDrop']);
// get result and assign variables (prefix with db)
$sessionqrystmt->execute();
$sessionqrystmt->bind_result($dbSessionId,$dbSessionDate,$dbSessionTime, $dbModuleId);
$sessionqrystmt->store_result();
$sessionnum = $sessionqrystmt->num_rows();
$dataArraySession = array();
while ( $sessionqrystmt->fetch() ) {
$dataArraySession[$dbModuleId]['Sessions'][$dbSessionId]['SessionDate'] = $dbSessoonDate['SessionTime'] = $dbSessionTime;
}
foreach ($dataArraySession as $sessionId => $sessionData) {
$sessionHTML = "";
$sessionHTML .= '<select name="session" id="sessionsDrop">'.PHP_EOL;
$sessionHTML .= '<option value="">Please Select</option>'.PHP_EOL;
$sessionHTML .= "<option value='$sessionId'>" . $sessionId . " - " . $sessionData['SessionDate']. " - " . $sessionData['SessionTime'] ."</option>".PHP_EOL;
$sessionHTML .= '</select>';
}
if ($sessionnum > 0) {
?>
<form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
<p>Sessions: <?php echo $sessionHTML; ?><input id="sessionSubmit" type="submit" value="Submit" name="sesionsubmit" /></p>
</form>
<?php
}
else {
echo "<p>Sorry, You have No Sessions under this Module</p>";
}
?>