php - 在一张表中垂直显示从数据库中检索到的数据

标签 php html mysql

我想要的是在 1 个表中显示检索数据。但是我需要表格行限制为10,然后转移到另一列

示例输出:

data1    data11
data2    data12
data3    data13
data4    data14
data5    data15
data6    data16
data7    data17
data8    data18
data9    data19
data10   data20

最佳答案

如果你想使用表格:

<?php

//assuming $data is an array which already contains your data
$data = array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);

$rowsPerColumn = 10;

$columns = ceil(count($data) / $rowsPerColumn);

echo '<table>';

for ($r = 0; $r < $rowsPerColumn; $r++)
{
    echo '<tr>';
    for ($c = 0; $c < $columns; $c++)
    {
        $cell = ($c * $rowsPerColumn) + $r;
        echo '<td>' . (isset($data[$cell]) ? $data[$cell] : '&nbsp;') . '</td>';
    }
    echo '</tr>';
}
echo '</table>';
?>

关于php - 在一张表中垂直显示从数据库中检索到的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27073746/

相关文章:

php - 为什么即使有访问 token ,地理定位帖子也不会出现在 API 中?

javascript - 是否可以在一个页面上有多个 Twitter Bootstrap 轮播?

javascript - Fabricjs - setBackgroundImage 为空 URL 导致 _setWidthHeight 中出现空引用错误

mysql - 在MYSQL select查询中,我们是否只需要传递 'INT'类型数据的int值?

使用日语文件名上传的 PHP 文件在数据库中变成损坏的文件名

php - 在 PHP 中,为什么不写入 test.txt?

php - Symfony 2 Form - 表单无效时刷新保护

php - 使用 PHP 填充下拉列表,不重复

javascript - 更改圆环图的边框颜色

MySQL Max 函数混合行