What is the best approach to populate a table with training dates from a database in PHP?

When populating a table with training dates from a database in PHP, the best approach is to fetch the dates from the database using a query, loop through the results, and dynamically generate table rows with the dates. This can be achieved by using PHP code to connect to the database, execute the query, fetch the results, and then loop through the results to display them in a table format.

<?php
// Connect to the database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "training_db";

$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// Fetch training dates from the database
$sql = "SELECT training_date FROM training_dates";
$result = $conn->query($sql);

// Display training dates in a table
if ($result->num_rows > 0) {
    echo "<table>";
    echo "<tr><th>Training Date</th></tr>";
    while($row = $result->fetch_assoc()) {
        echo "<tr><td>" . $row["training_date"] . "</td></tr>";
    }
    echo "</table>";
} else {
    echo "No training dates found";
}

$conn->close();
?>