How To Populate Html Table With Data From Mysql Database Using Php,Sql And Html Tutorial

How To Populate Html Table With Data From Mysql Database Using Php,Sql And Html Tutorial – Source Code?

How To Populate Html Table With Data From Mysql Database Using Php,Sql And Html Tutorial

By using this code you’ll be able to display data from mysql database on html table. You need to be connected to the database. Then query the table you want to select data from. You can either display the whole data from the table or limit the rows you want to be displayed on html table.


<?php
$connect = new mysqli("localhost", "root", "", "university");
if($connect != null){
 echo "connected";
}else {
 echo "failed to connect ";
}

$sqlQuery = "SELECT * FROM takes";
$qry = $connect->query($sqlQuery);

echo "<table><tr><th>ID</th><th>course_id</th><th>sec_id</th><th>semester</th><th>year</th><th>grade</th></tr>";
while($row = $qry->fetch_assoc()){
echo "<tr><td>".$row["ID"]."</td><td>".$row["course_id"].$row["sec_id"]."</td><td>".$row["semester"]."</td><td>".$row["year"]."</td><td>".$row["grade"]."</td><td></tr>";
}

echo "</table>";
?>

Leave a Reply

Your email address will not be published. Required fields are marked *