我知道这个问题与以前的帖子有点相似,但是我面临一些问题,我只需要指出正确的方向即可。我的模式内容完全来自单独的页面。
在模式中,我有一个select选项,它从数据库中填充,选择后,我单击show按钮,并显示数据库中的表。
<select class="" id="sess_ddl" name="sess_ddl" title="Select Session"> <!--Select Populates from database-->
<?php
echo "<option disabled selected hidden>Select Session</option>";
$result = mysqli_query($con, "SELECT * FROM sessions ORDER BY Begin desc") or die (mysqli_error());
while ( $row=mysqli_fetch_assoc($result)) {
echo "<option class='dropdown-content' value='".$row['SessionID'].
"'data-courses='".$row['Courses'].
"'>" . (date("d-m-Y", strtotime($row['Begin']))) . " | " . $row['Courses'] . "</option>";
}
?>
</select>
<button class="button button1" id="show_enr" name="show_enr">Show</button> <!--show_enr submit button-->
提交表格后,模式便消失了,我希望将获取的表显示在模式中。尝试了很多事情之后,如果这不起作用,我的最后选择将是不使用模式,因为提交时整个页面都会刷新。如果需要,下面是在提交时显示的表的代码。
<div id="enr_learners"> <!--Script shows table on show_enr button click based on selection-->
<?php
if (isset($_POST['show_enr'])) {
if (!empty($_POST['sess_ddl'])) {
$selected_sess = $_POST['sess_ddl'];
$qry1 = "SELECT * FROM enrollments WHERE SessionID = " . $selected_sess . "";
$result1 = mysqli_query($con, $qry1) or die (mysqli_error("Please select a session"));
if ($result1->num_rows > 0) {
echo "<table id='table_id' class='display' style='width:100%;'>
<thead>
<tr>
<th hidden>ID</th>
<th>SessionID</th>
<th>LearnerID</th>
</tr>
</thead>
<tbody>";
// output data of each row
while($row = $result1->fetch_assoc()) {
echo "<tr>";
echo "<td style='text-align:center' hidden>" . $row['ID'] . "</td>";
echo "<td style='text-align:center'>" . $row['SessionID'] . "</td>";
echo "<td style='text-align:center'>" . $row['LearnerID'] . "</td>";
echo "</tr>";
}
echo "</tbody>
<tfoot>
<tr>
<th></th>
<th></th>
</tr>
</tfoot>
</table>";
}
else {
echo "0 results";
}
} else {
echo "<div style='margin-top:10px; margin-bottom:10px; padding: 6px 0 7px 20px; background-color:#FADBD8; color:#C0392B;'>Please select a session!</div>";
}
}
?>
<hr style="margin-bottom:0; padding-bottom:0;" />
</div>
感谢您的帮助。