Php 试图显示表中列的内容,但我不知道将有多少列

Php 试图显示表中列的内容,但我不知道将有多少列,php,mysql,pdo,Php,Mysql,Pdo,到目前为止,我已经有了显示列的代码: $st = $db_pdo->prepare("DESCRIBE email"); $st->execute(); $rows = $st->fetchAll(PDO::FETCH_COLUMN); $column_array = array(); foreach ($rows as $row=>$key){ echo '<strong>'. strtoupper($key) . '</strong>

到目前为止,我已经有了显示列的代码:

$st = $db_pdo->prepare("DESCRIBE email");
$st->execute();
$rows = $st->fetchAll(PDO::FETCH_COLUMN);
$column_array = array();

foreach ($rows as $row=>$key){
    echo '<strong>'. strtoupper($key) . '</strong><br>'; 
}
等等等等

我想显示列的内容。就这样,没有别的,不修改它们,只显示内容

$stmt = $db_pdo->prepare("SELECT * FROM email");
$stmt->execute();
echo '<table>';
$first_row = true;
while ($row = $stmt->fetchAssoc()) {
    if ($first_row) {
        echo '<tr>';
        foreach (array_keys($row) as $column_name) {
            echo '<th>' . htmlentities($column_name) . '</th>';
        }
        echo '</tr>';
        first_row = false;
    }
    echo '<tr>';
    foreach ($row as $content) {
        echo '<td>' . htmlentities($content) . '</td>';
    }
    echo '</tr>';
}
echo '</table>';
$stmt = $db_pdo->prepare("SELECT * FROM email");
$stmt->execute();
echo '<table>';
$first_row = true;
while ($row = $stmt->fetchAssoc()) {
    if ($first_row) {
        echo '<tr>';
        foreach (array_keys($row) as $column_name) {
            echo '<th>' . htmlentities($column_name) . '</th>';
        }
        echo '</tr>';
        first_row = false;
    }
    echo '<tr>';
    foreach ($row as $content) {
        echo '<td>' . htmlentities($content) . '</td>';
    }
    echo '</tr>';
}
echo '</table>';
try {
    $pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); // Exclude the index count from the fetched array (the row).

    $stmt = $pdo->prepare('select * from email'); // You really don't need to put statements in uppercase (where are we in 1980?)
    $stmt->execute();
    while ($row = $stmt->fetch()) { // You need to loop and fetch the row to get the content.

         foreach ($row as $key => $val){
         echo '<strong>'. strtoupper($val) . '</strong><br>'; // Replaced $key to $val to get the content.
        }
    }
}
catch (PDOException $e) {
die(htmlspecialchars($e->getMessage()));
}