다음과 같이 테이블에 달 (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
나는 몇 가지 방법을 시도
,하지만 행운을 다음과 같이 수직으로 테이블을 표시하는 방법입니다. 나는 내가 시도한 것에 대해 당신에게 약간의 코드를 보여줄 수 있었으면 좋겠지 만, 나는 보여줄 것이 전혀 없다.
누군가이 테이블을 유심히 표시하는 방법을 알고 있습니까?
dev-null-dweller 감사합니다. 그것은 완벽하게 작동했습니다. – librium