如何打印 table 的所有结果而不需要逐个变量打印?

How to print all the results of a table without the need to print variable by variable?

一些更简单的方法可以将所有这些结果打印在两列 table 中,其中包含数据的相应列名称 table,而无需逐个变量地打印。

我正在使用面向对象的 mysqli PHP,没有使用 PDO,请不要这样:(fetchAll(PDO::FETCH_ASSOC);).

    $stmt->execute();
    $stmt->store_result();
    $stmt->bind_result(
        $id_logtrama, $fechaHora, $idCliente,
        $idEquipo, $statusGlobal, $temp,
        $tempAmb, $hrelAmb, $presion,
        $termopar1, $termopar2, $volt_fase1,
        $amps_fase1, $frec_fase1, $fpot_fase1,
        $volt_fase2, $amps_fase2, $frec_fase2, $fpot_fase2, 
        $volt_fase3, $amps_fase3, $frec_fase3, $fpot_fase3, 
        $status_temp, $status_tempAmb, $status_hrelAmb, $status_presion,
        $status_termopar1, $status_termopar2, $status_volt_fase1,
        $status_amps_fase1, $status_frec_fase1, $status_fpot_fase1,
        $status_volt_fase2, $status_amps_fase2, $status_frec_fase2,
        $status_fpot_fase2, $status_volt_fase3, $status_amps_fase3,
        $status_frec_fase3, $status_fpot_fase3, $trama
    );
    while ($stmt->fetch()) {}

我假设这是一行有很多列,但即使你有多行,使用 $res = $stmt->store_result(); 获取结果集,然后你可以将行作为关联数组获取并处理每一列它的名称和值在这样的内部 foreach 循环中

    $stmt->execute();
    $res = $stmt->store_result();
?>
    <table class="table table-bordered">
<?php
    # Fetch each row from resultset
    while ( $row = $res->fetch_assoc() ){
        # for each row process each column
        foreach ($row as $name => $val ) {

            echo "
                <tr>
                    <td width='30%'><label>$name</label></td>
                    <td width='70%'>$val</td>
                </tr>";
        }
    }