I know it must be something very silly I'm missing here. I have a table and all calculations are working great. I'm stuck here:
After while loop I can echo ttl_sold and all other information everything except "balance".
in while loop these are fine and I get results:
$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql); ?>
<?php
$sum = $sum + $rows['total'];
$ttlsold = $ttlsold + $rows['quantity'];
?>
<?php
$sum = 0;
$ttlsold = 0;
while($rows=mysql_fetch_array($result)){
ttl_sold is 12 and when I echo "balance" I get -12. I did try to include this within the loop and outside, but still no luck!
<?php
$balance = "SELECT stock FROM tbl_name WHERE id = 1";
$balance = $balance - $ttl_sold;
?>
<table width="1000" border="1" cellspacing="0" cellpadding="3">
<tr>
<td width="100"><?php echo $balance; ?></td>
Any idea? Thanks!