Outputting multidimensional array
Posted: Mon Jun 20, 2005 7:50 am
I have an array which is generated by:
which is put in an array by:
The array then looks like this:
This shows the total profit for each employee for each day.
Now, my problem is that I have big issues outputting this propperly to HTML. Ideally, I would like for the employee names to be headers and then on subsequent rows show dates and profits for each employee. Like so:
As you can see, some employees do not have any profits on certain dates which partly contributes to messing up my output.
If anyone could help me with this I would be absolutely super duper happy and greatful
Code: Select all
SELECT SUM(p.profit) AS profit, e.name, p.time
FROM profit p, emp e
WHERE e.eid=p.eid
AND DATE_FORMAT(p.time, '%M-%Y')='June-2005'
GROUP BY e.name, p.time
ORDER BY e.nameCode: Select all
<?
while($row = mysql_fetch_array($result))
{
$array[$row['name']][$row['time']] = $row['profit'];
}
?>Code: Select all
Array
(
їAlan] => Array
(
ї17-June-2005] => 5060
ї18-June-2005] => 1009
ї20-June-2005] => 344
)
їJames] => Array
(
ї18-June-2005] => 1797
ї19-June-2005] => 1779.33
)
їJohn] => Array
(
ї18-June-2005] => 1266
ї19-June-2005] => 907.26
ї20-June-2005] => 122
)
)Now, my problem is that I have big issues outputting this propperly to HTML. Ideally, I would like for the employee names to be headers and then on subsequent rows show dates and profits for each employee. Like so:
Code: Select all
<table border="e;0"e; cellspacing="e;0"e; cellpadding="e;1"e;>
<tr>
<td>Date</td>
<td>Alan</td>
<td>James</td>
<td>John</td>
<td>SUM</td>
</tr>
<tr>
<td>17-June-2005</td>
<td>5060</td>
<td>0</td>
<td>0</td>
<td>xxx</td>
</tr>
<tr>
<td>18-June-2005</td>
<td>1009</td>
<td>1797</td>
<td>1266</td>
<td>yyy</td>
</tr>
<tr>
<td>19-June-2005</td>
<td>0</td>
<td>1799</td>
<td>907</td>
<td>xxx</td>
</tr>
<tr>
<td>20-June-2005</td>
<td>344</td>
<td>0</td>
<td>122</td>
<td>yyy</td>
</tr>
</table>If anyone could help me with this I would be absolutely super duper happy and greatful