【发布时间】:2020-03-19 05:25:54
【问题描述】:
我想创建一个表,我可以在其中放置一些数据库中的数据。但方式不同。(就像图片一样)
在这张图片中..“Csc 1st 101”在第一行第一列,“csc 1st 102”在第二行第二列。 我想以这种方式创作。请帮帮我。
【问题讨论】:
-
显示 SQL 查询以检索您想要的数据,然后描述您希望该数据如何出现在 HTML 表中。
标签: php mysql html-table
我想创建一个表,我可以在其中放置一些数据库中的数据。但方式不同。(就像图片一样)
在这张图片中..“Csc 1st 101”在第一行第一列,“csc 1st 102”在第二行第二列。 我想以这种方式创作。请帮帮我。
【问题讨论】:
标签: php mysql html-table
试试这个
<table style="width:100%">
<tr>
<th>num1</th>
<th>num2</th>
<th>num3</th>
</tr>
<tr>
<?php
$perRow= 3;
$arr = array('Csc 1st 101', 'Csc 1st 102', 'Csc 1st 103', 'Csc 1st 201','Csc 1st 202','Csc 1st 203','Csc 1st 301','Csc 1st 302','Csc 1st 303');
$i = 0;
foreach ($arr as &$value) {
$i++;
echo '<th>'. $value .'</th>';
if ($i % $perRow == 0){
echo '</tr><tr>';}
}
?>
</table>
如果您想在每行显示更多值,您可以更改 $perRow
【讨论】: