我有一个弹出窗体从用户获取数据并将其添加到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>
add.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
答案 0 :(得分:1)
您可以通过多种方式实现这一目标。中国牛市的方法是:
<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>
答案 1 :(得分:0)
在您的主页上执行提取查询。为此,使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文件中执行PHP代码