<?php
    
// print_r($records);

$columns = [];
foreach ($records as $index => $row) {
    $records[$index] = json_decode($row['data'], 1);
    
    foreach ($records[$index] as $column => $value) {
        $columns[$column] = $column;
    }
}

// print_r($records);

?>
<table>
    <thead>
        <tr>
            <?php
                
                foreach ($columns as $c) {
                    echo "<th>$c</th>";
                }
                
            ?>
        </tr>
    </thead>
    <tbody>
        <?php
            
            foreach ($records as $row) {
                echo '<tr>';
                foreach ($columns as $col) {
                    $value = $row[$col];
                    if (is_array($value)) {
                        $value = implode(', ', $value);
                    }
                    echo "<td style='min-width:400px;'>{$value}</td>";
                }
                echo '</tr>';
            }
                
        ?>
    </tbody>
</table>
