I have to build html table that will look like this:
But the fields and head names I get from database. First query - returns fields description, second query reurns fields values. I spent a lot hours trying to reach this. So what I do:
<table>
<tbody>
<?php
foreach ($comments as $comment) { // $comments is array of strings
?>
<td><b><?= $comment ?></b></td>
<?php}?>
</tbody>
<?php
foreach ($field_names as $fn) { // $field_names is array_keys($result)
?><tr><?php
foreach ($result as $r) { // $result - values of fields
?>
<td><?= $r[$fn] ?></td>
<?php
}?>
</tr>
<?php
}
?></table>
But in this way I'm getting my content transposed. Any help, thanks.
ok, since you didnt provide the variable information, i will assume the following, and if so, this code should work for you:
<?php
$comments = ["comm1", "comm2", "comm3"]; // $comments is array of strings
$field_names = array(
0 => "fv1",
1 => "fv2",
2 => "fv3"
); // $field_names is array_keys($result)
$result = ["value1", "val2", "val3"]// $result - values of fields
?>
<table>
<thead>
<tr>
<?php foreach ($comments as $comment) { ?>
<th><b><?= $comment ?></b></th>
<?php } ?>
</tr>
</thead>
<tbody>
<tr>
<?php foreach ($field_names as $k => $v) { ?>
<td><?= $result[$k] ?></td>
<?php } ?>
</tr>
</tbody>
</table>
UPDATE:
<style>
.tbl_hdr{
font-weight: bold;
}
</style>
<?php
$comments = ["comm1", "comm2", "comm3"]; // $comments is array of strings
$field_names = array(
0 => "fv1",
1 => "fv2",
2 => "fv3"
); // $field_names is array_keys($result)
$result = ["value1", "val2", "val3"]// $result - values of fields
?>
<table>
<?php foreach ($field_names as $k => $v) { ?>
<tr>
<td class="tbl_hdr"><?= $comments[$k] ?></td>
<td><?= $result[$k] ?></td>
</tr>
<?php } ?>
</table>