Wednesday, April 23, 2025

MySQLi Html Table Report

html_table_report.php


<?php
//Config

$server = "localhost";
$user = "root";
$password = "";
$database = "address_book";

//Establishing a Connection to MySQL Server
$connection = mysqli_connect($server, $user, $password, $database);

//Check Connection
if (!$connection) {
	die("<h2>Total Fail</h2> " . mysqli_connect_error());
} else {
	echo "Connection Successfull <br>";
}

//SQL Command
$sql_command = "SELECT * FROM people";
$action = mysqli_query($connection, $sql_command);

echo "<h1>Results: </h1>";
echo "<table width='80%' cellspan='2' border='2'><tr bgcolor='yellow'>";
echo "<td>ID</td>";
echo "<td>Name</td>";
echo "<td>Lastname</td>";
echo "<td>Telephon</td>";
echo "<td>email</td>";
echo "<td>Address</td>";
echo "<td>Data/Time</td></tr>";

while ($line = mysqli_fetch_assoc($action)) {
	echo "<tr><td>" . $line["id"] . "</td>
	<td>" . $line["name"] . "</td>
	<td>" . $line["lastname"] . "</td>
	<td>" . $line["telephon"] . "</td>
	<td>" . $line["email"] . "</td>
	<td>" . $line["address"] . "</td>
	<td>" . $line["meta"] . "</td>";
	
}
echo "</table>";

?>

This PHP code will retrieve all the data from the "people" table in the MySQL database and display it in an HTML table.

The code first runs a SQL SELECT query to retrieve all the data from the "people" table. Then, it uses a while loop and mysqli_fetch_assoc() function to retrieve each row of data one at a time. For each row, it echoes an HTML table row with the data from the columns, enclosed in table cells.

The table structure is defined at the beginning of the loop, and the table cells are populated with the values from the query results.

At the end of the loop, the PHP code closes the HTML table tag. The resulting output will be an HTML table showing all the data from the "people" table.

Nice Html Table Report:


Connection Successfull
Results:
ID	Name	Lastname	Telephon	email	Address	Data/Time
1	Samantha	Fox	555444	mail@server.com	Main Road 12a	2020-07-25 12:01:51
2	Samantha	Fox	555444	mail@server.com	Main Road 12a	2020-07-25 12:04:28
3	Samantha	Fox	555444	mail@server.com	Main Road 12a	2020-07-25 12:04:29

No comments:

Post a Comment

Tkinter Introduction - Top Widget, Method, Button

First, let's make shure that our tkinter module is working ok with simple  for loop that will spawn 5 instances of blank Tk window .  ...