<table>
<tr>
<td>Nama</td><td>Hari</td><td>Jumlah</td><td>Diminta</td><td>Sisa</td>
</tr>
<?php
$hs = mysql_query("select * from A");
while($A = mysql_fetch_array($hs)){
$hs2 = mysql_query("select * from B where nama='".$A['nama']."' order by hari");
$jumlah = $A['jumlah'];
while($B = mysql_fetch_array($hs2)){
$sisa = $jumlah - $B['diminta'];
echo '<td>'.$B['nama'].'</td><td>'.$B['hari'].'</td><td>'.$jumlah.'</td><td>'.$B['diminta'].'</td><td>'.$sisa.'</td>';
$jumlah = $sisa;
}
}
?>
</table>