Php 如何水平打印表格,而不是像这里那样垂直打印?

Php 如何水平打印表格,而不是像这里那样垂直打印?,php,html,mysql,sql,Php,Html,Mysql,Sql,这是我尝试过的,表格是垂直打印的,带有我想要的单位和百分比,但所有的都是垂直的。我希望单位和百分比是垂直的,但是下一个单位和百分比与上一个单位和百分比是水平的,但在它们方面也是垂直的 这就是我希望它看起来的样子: 单位单位单位单位单位 percpercpercpercperc $table = ''; $table .= '<table border="1">'; foreach ($gradebook as $row) { $table

这是我尝试过的,表格是垂直打印的,带有我想要的单位和百分比,但所有的都是垂直的。我希望单位和百分比是垂直的,但是下一个单位和百分比与上一个单位和百分比是水平的,但在它们方面也是垂直的

这就是我希望它看起来的样子:

单位
单位
单位
单位
单位

perc
perc
perc
perc
perc

$table = '';
    $table .= '<table border="1">';
     foreach ($gradebook as $row) 
    { 
        $table .=  '<tr>';
        $table .= '<td>' . $row['unit'] . '</td>';
        $table .= '</tr>';
        $table .=  '<tr>';
        $table .= '<td>' . $row['percent'] . '</td>';
        $table .= '</tr>';
    }
    $table .= '</table>';
print($table);

您只需在数组中迭代两次:

$table .= '<table border="1">';
$table .=  '<tr>';
foreach ($gradebook as $row) 
{ 
    $table .= '<td>' . $row['unit'] . '</td>';
}
$table .= '</tr>';
$table .=  '<tr>';
foreach ($gradebook as $row) 
{ 
    $table .= '<td>' . $row['percent'] . '</td>';
}
$table .= '</tr>';
$table .= '</table>';
$table.='';
$table.='';
foreach($成绩册作为$行)
{ 
$table.=''.$row['unit'].';
}
$table.='';
$table.='';
foreach($成绩册作为$行)
{ 
$table.=''.$row['percent'].';
}
$table.='';
$table.='';
因此,为每个字段组成一行(
tr

$table .= '<table border="1">';
$table .=  '<tr>';
foreach ($gradebook as $row) 
{ 
    $table .= '<td>' . $row['unit'] . '</td>';
}
$table .= '</tr>';
$table .=  '<tr>';
foreach ($gradebook as $row) 
{ 
    $table .= '<td>' . $row['percent'] . '</td>';
}
$table .= '</tr>';
$table .= '</table>';