Using PHP and MySQL, how can I convert the below table:
id employee failures frequency
---------------------------------------------
1 khalil battery failure 2
2 khalil windows failure 0
3 khalil virus attack 3
4 yuzri battery failure 3
5 yuzri windows failure 0
6 yuzri virus attack 2
7 arthur battery failure 0
8 arthur windows failure 3
9 arthur virus attack 3
10 ashley battery failure 1
11 ashley windows failure 4
12 ashley virus attack 1
to this table:
failure khalil yuzri arthur ashley
------------------------------------------------
battery failure 2 3 0 1
windows failure 0 0 3 4
virus attack 3 2 3 1
I have three tables (as follows):
employee table has eid, ename
failure table has fid, failure
frequency table has qid, frequency, eid, fid
For the first table, I joined it using PHP and MySQL like shown in the below code:
<table align="center" cellpadding="1" cellspacing="1" bordercolor="#000000" border="1">
<tr align="center" bgcolor="#FFD700">
<td align="center"><strong>ID</strong></td>
<td align="center"><strong>EMPLOYEE</strong></td>
<td align="center"><strong>FAILURES</strong></td>
<td align="center"><strong>FREQUENCY</strong></td>
<td align="center"><strong>DEPARTMENT</strong></td>
</tr>
<?php
$sql="SELECT * FROM employees INNER JOIN frequency ON employees.eid=frequency.eid INNER JOIN f_types ON frequency.fid=f_types.fid ORDER BY frequency.qid";
$result=mysql_query($sql);
while($row = mysql_fetch_array($result)){
?>
<tr align="center">
<td align="center"><div><?php echo $row['qid']; ?></div></td>
<td align="center"><div><?php echo $row['ename']; ?></div></td>
<td align="center"><div><?php echo $row['failure']; ?></div></td>
<td align="center"><div><?php echo $row['frequency']; ?></div></td>
<td align="center"><div><?php echo $row['dept']; ?></div></td>
</tr>
<?php } ?>
</table>
The second table is where I am having problem because its horizontal and each row has two fields from two different tables. (i.e. failure and frequency).