0

I have a pop-up form which gets data from a user and adds it into the MySQL phpmyadmin table, i want to be able to display this data within a html table once the popup closes, after i click submit i am directed back to the homepage, where I want the data to be displayed on the table.

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");

I am new to html and php unsure how I can link this to the html

castis
  • 8,154
  • 4
  • 41
  • 63
  • so whats the problem just select data and display on another page or send a json http://stackoverflow.com/a/19027741/3841803 – singhakash Feb 09 '15 at 19:14

2 Answers2

0

Execute a fetch query on your home page. For that make M.html to M.php and execute the query to fetch data from your database.

<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 - You can't execute your PHP code in .html files

Moid
  • 1,447
  • 1
  • 13
  • 24
0

You can do this a number of ways. The bull-in-the-China-shop method is this:

<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>
Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119