How can PHP be used to automatically export data from a database table to HTML, excluding a specific column like the ID column?
To automatically export data from a database table to HTML using PHP, excluding a specific column like the ID column, you can fetch the data from the database and then loop through each row to create HTML table rows, excluding the specific column during the loop iteration.
<?php
// Connect to the database
$pdo = new PDO('mysql:host=localhost;dbname=database_name', 'username', 'password');
// Fetch data from the database table
$stmt = $pdo->query('SELECT * FROM table_name');
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
// Output HTML table
echo '<table>';
foreach ($rows as $row) {
echo '<tr>';
foreach ($row as $key => $value) {
if ($key !== 'id') {
echo '<td>' . $value . '</td>';
}
}
echo '</tr>';
}
echo '</table>';
?>