<?php
$host = "localhost";
$user = "username_here";
$pass = "password_here";
$db_name = "database_name_here";
//create connection
$connection = mysqli_connect($host, $user, $pass, $db_name);
//test if connection failed
if(mysqli_connect_errno()){
die("connection failed: "
. mysqli_connect_error()
. " (" . mysqli_connect_errno()
. ")");
}
//get results from database
$result = mysqli_query($connection,"SELECT * FROM products");
$all_property = array(); //declare an array for saving property
//showing property
echo '<table class="data-table">
<tr class="data-heading">'; //initialize table tag
while ($property = mysqli_fetch_field($result)) {
echo '<td>' . $property->name . '</td>'; //get field name for header
array_push($all_property, $property->name); //save those to array
}
echo '</tr>'; //end tr tag
//showing all data
while ($row = mysqli_fetch_array($result)) {
echo "<tr>";
foreach ($all_property as $item) {
echo '<td>' . $row[$item] . '</td>'; //get items using property value
}
echo '</tr>';
}
echo "</table>";
?>
Code Example |
---|
Html :: height 100% tailwind |
Html :: HTML <mark Element |
Html :: how to make check boxes in html |
Html :: how to do a line break in html |
Html :: check html |
Html :: aria list |
Html :: striped table bootstrap |
Html :: html special characters |
Html :: slider input |
Html :: h5 in html |
Html :: underline |
Html :: html flag icons |
Html :: html span tag |
Html :: iframe ember pdf |
Html :: prettier html formatting |
Html :: how to create check in html? |
Html :: create link inertia-svelte |
Html :: Text with colour bold |
Html :: mat-form date pickerwith hints |
Html :: pyscript |
Html :: inline heading and input |
Html :: make link open in new tab |
Html :: html relative path go back one directory |
Html :: sample code html header template code |
Html :: proper center grid |
Html :: data tables in html |
Html :: rounded scrolling images |
Html :: navbar in rows in bootstrap |
Html :: animate text |
Html :: sample html template |