将表格呈现为“错误”方式:转置列和行? [英] Render a Table the "wrong" way: transpose Columns and Rows?
本文介绍了将表格呈现为“错误”方式:转置列和行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道是否有一种简单的方法来使用标准绘制表格(mysql_fetch_assoc),其中最左边的列是这样的标题:
I'm wondering if there is an easy way to draw a table using the standard while(mysql_fetch_assoc) where the left most column is the header like this:
Name | Peter Jacksson | Steven Spielberg | Martin Scorsese |
Birthyear | 1961 | 1946 | 1942 |
Movie | Lord of the Rings | Jurassic Park | Cape Fear |
(老鼠!SO不支持table-tag)。
(Rats! SO doesn't support the table-tag).
推荐答案
我会通过将元素添加到数组结构然后打印该结构来实现此目的:
I would do this by adding the elements to an array structure and then printing that structure:
$data = array('name' => array(), 'birth' => array(), 'movie' => array());
while($r = mysql_fetch_assoc(...)) {
$data['name'][] = $r['name'];
...
}
echo '<th>Name</th>';
foreach($data['name'] as $n) {
printf('<td>%s</td>', htmlspecialchars($n));
}
...
这篇关于将表格呈现为“错误”方式:转置列和行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文