我有一个弹出表单,它从用户那里获取数据并将其添加到MySQL phpmyadmin表中,我希望在弹出窗口关闭后能够在html表中显示这些数据,在我单击提交后,我会被引导回主页,在那里我希望数据显示在表上。
M.html
<thead>
<tr>
<th scope="col" colspan="2">CRN</th>
<th scope="col" colspan="6">Title</th>
<th scope="col" rowspan="2">Co-Ordinator</th>
<th scope="col" colspan="6">Coursework Number</th>
<th scope="col" rowspan="2">Contribution</th>
<th scope="col" colspan="6">Edit</th>
<th scope="col" rowspan="2">Upload</th>
<th scope="col" colspan="6">Manage Grades</th>
</tr>
</table>
添加.php
$display_query = "SELECT CRN, Title, Co-Ordinator, CourseworkNumber, Contribution FROM Modules";
$displayresult = mysqli_query($con, $display_query);
$num = mysql_numrows($displayresult);
mysqli_close($con);
header("Location: ../views/M.html");
我是html和php的新手,不确定如何将其链接到html
您可以通过多种方式来实现这一点。中国商店的牛市方法是这样的:
<thead>
<tr>
<th scope="col" colspan="2">CRN</th>
<th scope="col" colspan="6">Title</th>
<th scope="col" rowspan="2">Co-Ordinator</th>
<th scope="col" colspan="6">Coursework Number</th>
<th scope="col" rowspan="2">Contribution</th>
<th scope="col" colspan="6">Edit</th>
<th scope="col" rowspan="2">Upload</th>
<th scope="col" colspan="6">Manage Grades</th>
</tr>
<?php
$display_query = "SELECT CRN, Title, Co-Ordinator, CourseworkNumber, Contribution FROM Modules";
$displayresult = mysqli_query($con, $display_query);
while($row = mysqli_fetch_assoc($display_query)) { // loop through the returned rows
// output each elemment
echo '<tr>';
echo '<td>' . $row['CRN'] . '</td>';
// other column items in the same fashion
echo '</tr>';
}
mysqli_close($con);
?>
</table>
在主页上执行获取查询。为此,将M.html
设置为M.php
,并执行查询以从数据库中获取数据。
<table>
<th> <!--table headers--> </th>
<?php
$query = $con ->query(SELECT * FROM Modules);
while($row = $query->fetch){
echo '<tr>';
echo '<td>'.$row['CRN'].'</td>';
echo '<td>'.$row['Title'].'</td>';
echo '<td>'.$row['Co-Ordinator'].'</td>';
echo '<td>'.$row['CourseworkNumber'].'</td>';
echo '<td>'.$row['Contribution'].'</td>';
echo '</tr>'
}
?>
</table>
PS-你不能在.html文件