Hi there. I'm trying to summarize the equipment shipped and equipment received. The shiplist table contains....
item quantity
apples 1
apples 3
oranges 3
oranges 3
The receive table contains...
equipment quantity
apples 10
apples 10
grapes 10
My code is as follows...
//get equipment list
$equiplist= "select shiplist.item, sum(shiplist.quantity) as 'shippedsum', sum(receive.quantity) as 'receivedsum'
from shiplist
left join receive on receive.equipment = shiplist.item
group by shiplist.item";
$equipresult=mysql_query($equiplist) or print (mysql_error());
echo "<p align='center'><font size='4'><b>Inventory </b></font></p>";
print "<br>";
print "<table border=1 width=70% cellpadding=1 cellspacing=1 align=center>";
print "<tr>
<td width=35%><font size='2'>Equipment</font></td>
<td width=8%><font size='2'>Shipped</font></td>
<td width=8%><font size='2'>Received</font></td>
<td width=8%><font size='2'>On Hand</font></td>
</tr>
</table>";
while ($row= mysql_fetch_array($equipresult))
{ extract($row);
$onhand=$receivedsum-$shippedsum;
$onhand = ( $onhand <= 0 ) ? '<span style="color: red">'.$onhand.'</span>' : $onhand;
print "<table border=1 width=70% cellpadding=1 cellspacing=1 align=center>";
print "<tr>
<td width=35%><font size='2'>$item</font></td>
<td width=8%><font size='2'>$shippedsum</font></td>
<td width=8%><font size='2'>$receivedsum</font></td>
<td width=8%><font size='2'>$onhand</font></td>
</tr>
</table>";}
?>