show mysql table data in html code example
Example: mysql data to html table
<?php
$host = "localhost";
$user = "username_here";
$pass = "password_here";
$db_name = "database_name_here";
$connection = mysqli_connect($host, $user, $pass, $db_name);
if(mysqli_connect_errno()){
die("connection failed: "
. mysqli_connect_error()
. " (" . mysqli_connect_errno()
. ")");
}
$result = mysqli_query($connection,"SELECT * FROM products");
$all_property = array();
echo '<table class="data-table">
<tr class="data-heading">';
while ($property = mysqli_fetch_field($result)) {
echo '<td>' . $property->name . '</td>';
array_push($all_property, $property->name);
}
echo '</tr>';
while ($row = mysqli_fetch_array($result)) {
echo "<tr>";
foreach ($all_property as $item) {
echo '<td>' . $row[$item] . '</td>';
}
echo '</tr>';
}
echo "</table>";
?>