2015-02-09 131 views
0

我有一个弹出形式从用户获得数据并将其添加到MySQL的phpMyAdmin的表,我希望能够以一个HTML表格一旦弹出关闭中显示这个数据,在我点击提交后,我被引导回主页,在那里我想让数据显示在桌面上。显示MySQL数据与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

有啥问题只是选择另一页上的数据和显示或发送JSON http://stackoverflow.com/a/19027741/3841803 – silentprogrammer 2015-02-09 19:14:14

回答

1

您不能执行PHP代码中你可以这样做多种方式。在牛市中,在中国的商店方法是这样的:

<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> 
+0

我是否将html代码从M.html文件中取出并放入add.php中? – 2015-02-09 19:49:41

+0

你可以,或者你可以在M.html文件中加入add.php。 – 2015-02-09 20:19:13

+1

*“牛仔在中国店”* - 祝大家新年快乐;-) – 2015-02-11 20:25:44

0

上执行fetch查询您的主页。为此,请从M.htmlM.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文件