How to fetch database table data and display it in HTML table?
php How to fetch database table data and display it in HTML table? PHP And HTML Table
Fetch data from database table and display it into the HTML table
For displaying the data into the HTML table, first we have to create the HTML table with heading row and body row.
HTML Table to display data from database
<table border=1>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Username</th>
<th>Password</th>
<th>Update</th>
<th>Delete</th>
</tr>
<tr>
<td>First Name from Database</td>
<td>Last Name from Database</td>
<td>Username from Database</td>
<td>Password from Database</td>
<td><a href="update.php">Update</a></td>
<td><a href="delete.php">Delete</a></td>
</tr>
</table>
Sample HTML table
First Name
Last Name
Username
Password
Update
Delete
First Name from Database
Last Name from Database
Username from Database
Password from Database
To fetch the existing data from the database we need to learn the query that how to write the fetch query, and we will use the two PHP mysqli functions.
1- mysqli_query()
2- mysqli_fetch_assoc()
You can visit the detail fetch query tutorial $t30D8 Database fetch data using PHP
Full HTML and PHP Source Code for displaying record from database table into HTMl table
Note ! We can print the id at UPDATE and DELETE button , this id will pass as GET request to respective update.php and delete.php pages. We will discuss the update and delete tutorial in next tutorials.