This is partly PHP, partly javascript, so I wasn't sure where to stick it, but I'll stick it here. I'm sorry if this is a bit confusing, but I hope I can explain myself well.
The below code queries a table in my database, and prints out a table with those values. The embedded javascript enables you to change the values in some of the fields, and the other fields will automatically update using the "onchange" event handler. I'm a little experienced with php, and extremely new at javascript. Anyway, here's the code, and my question will follow:
$query="SELECT * from categories";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result))
{
$balance=$row['balance']/100;
$allotment=$row['allotment']/100;
$total=$balance+$allotment;
$name=$row['name'];
$id=$row['id'];
$left=$net-$sum;
echo "<tr>
<td align='right'>$name</td>
<td>$<input type='text' value='$balance' name='balance$id' readonly size=8 ></td>
<td>$<input type='text' value='$allotment' name='allotment$id' size=8 onchange='total$id.value = ((allotment$id.value*100) + (balance$id.value*100))/100;'></td>
<td>$<input type='text' value='$total' name='total$id' align='right' size=8 readonly></td>
</tr>";
}
So it basically prints out a table of values, but since they're in a loop, and not necessarily being pulled from my database, I don't know how to pull the totals. What I would like to do is pull the sum from the "allotment" field. Is this possible? Again, I'm sorry if I don't make any sense, but if anyone can help, I'd appreciate it.
Thanks.