I'm trying to figure out how to turn the data output from a query onto it's side - but I just can't work out how to do it.
Currently the query looks like this:
Code: Select all
$query="select year, low, mid, high, peak from uk_rates ORDER BY year ASC";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
$i=0;
while ($i < $num) {
$year=mysql_result($result,$i,"year");
$low=mysql_result($result,$i,"low");
$mid=mysql_result($result,$i,"mid");
$high=mysql_result($result,$i,"high");
$peak=mysql_result($result,$i,"peak");
?>
<table>
<thead>
<tr>
<th>Year</th>
<th>Low Season<br />Jan/Feb<br />Oct/Nov</th>
<th>Mid Season<br />Mar/Apr/May<br />June/Sep</th>
<th>High Season<br />Jul/Aug</th>
<th>Peak Season<br />Christmas<br />New Year</th>
</tr>
</thead>
<tbody>
<?
$i=0;
while ($i < $num) {
$year=mysql_result($result,$i,"year");
$low=mysql_result($result,$i,"low");
$mid=mysql_result($result,$i,"mid");
$high=mysql_result($result,$i,"high");
$peak=mysql_result($result,$i,"peak");
?>
<tr>
<td><? echo $year; ?></td>
<td><? echo $low; ?></td>
<td><? echo $mid; ?></td>
<td><? echo $high; ?></td>
<td><? echo $peak; ?></td>
</tr>
<?
$i++;
}
echo "</table>";
}
But I'd like it to look like this:

However I can't figure out how to do this as I can't just cycle through rows with this approach.
(once I get it working I plan on making it a little "cleaner" I just need to figure out the approach required!)
Any advice gratefully accepted!