我正在尝试在 PHP 中创建一个表,其中我将有一堆由表单设置的列标题,然后该表将仅显示这些列。
因此,表格可能有 4 列或 6 列,具体取决于输入的日期范围。
最好的方法是什么,因为我已经尝试了一些东西,但没有什么能接近我想要的。
这是一些代码:
echo '<table>';
echo '<tr>';
echo '<th>Last Name</td>';
echo '<th>First Name</td>';
if($column_date1 != '') { echo '<th>' . $column_date1 . '</td>'; }
if($column_date2 != '') { echo '<th>' . $column_date2 . '</td>'; }
if($column_date3 != '') { echo '<th>' . $column_date3 . '</td>'; }
if($column_date4 != '') { echo '<th>' . $column_date4 . '</td>'; }
if($column_date5 != '') { echo '<th>' . $column_date5 . '</td>'; }
echo '</tr>';
// I will have a loop in here that searches records in a database.
$mysqliFunctionResult = $mysqliFunction->query($mysqliFunctionQuery);
while($line = $mysqliFunctionResult->fetch_assoc()) {
?><tr>
<td><?php echo $line['tabledata1']; ?></td>
<td><?php echo $line['tabledata2']; ?></td>
<td><?php echo $line['tabledata3']; ?></td>
<td><?php echo $line['tabledata4']; ?></td>
<td><?php echo $line['tabledata5']; ?></td>
</tr>
<?php } ?>
</table>