我有一張表格,如下所示在表格中顯示月份(1月至12月)。
該表從數據庫中獲取值,但不是固定的。垂直顯示月份名稱而不是水平
<table width="100%" style="font-size:9px">
<thead>
<tr>
<th colspan="14" style="text-align:center">Year: <?PHP echo $year?></th>
</tr>
<tr >
<th>Jan</th>
<th>Feb</th>
<th>Mar</th>
<th>Apr</th>
<th>May</th>
<th>Jun</th>
<th>Jul</th>
<th>Aug</th>
<th>Sep</th>
<th>Oct</th>
<th>Nov</th>
<th>Dec</th>
<th>Total</th>
</tr></thead><tbody>
<tr >
<?PHP
for ($i=1; $i<=12; $i++) {
$yearstart = $year."-".$i."-01";
$yearend = $year."-".$i."-31";
$sql="SELECT SUM(total) as totalsales_$i from salesorder where user_id=7 and created BETWEEN '$yearstart' AND '$yearend' ";
$res = $db->sql_query($sql);
$row = $db->sql_fetchrow($res);
$total = $total + $row['totalsales_'.$i];
?>
<td style="width: 96px; text-align:right">
<?PHP if ($row['totalsales_'.$i] !='')
echo "$".number_format($row['totalsales_'.$i],2);
else
echo "<font color=#c2c2c2>$0.00</font>";?>
</td>
<?PHP //for ?>
<td style="text-align:right"><?PHP echo "$".number_format($total,2) ;?></td>
</tr>
</tbody></table>
OUTPUT:
Jan feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec Total
$0 $0 $0 $0 $0 $0 $0 $0 $0 $0 $0 $0 $0
$0 $0 $0 $0 $0 $0 $0 $0 $0 $0 $0 $0 $0
$0 $0 $0 $0 $0 $0 $0 $0 $0 $0 $0 $0 $0
...
...
但我需要的是如何垂直顯示錶,如下
2011 2012 2013 ...
Jan $0.00 $0.00 $0.00 $0.00
feb $0.00 $0.00 $0.00 $0.00
Mar $0.00 $0.00 $0.00 $0.00
Apr $0.00 $0.00 $0.00 $0.00
May $0.00 $0.00 $0.00 $0.00
Jun $0.00 $0.00 $0.00 $0.00
Jul $0.00 $0.00 $0.00 $0.00
Aug $0.00 $0.00 $0.00 $0.00
Sep $0.00 $0.00 $0.00 $0.00
Oct $0.00 $0.00 $0.00 $0.00
Nov $0.00 $0.00 $0.00 $0.00
Dec $0.00 $0.00 $0.00 $0.00
Total $0.00 $0.00 $0.00 $0.00
我嘗試了幾種不同的方式,但沒有運氣。我希望我可以在這裏向你展示一些關於我所嘗試的代碼,但我真的沒有表現出來。
有沒有人有任何想法如何顯示這張表vefully?
謝謝dev-null-dweller。它工作完美。 – librium