I am trying to fetch SUM(WeightKgs) column and sum up each field to <=2000. Once it gets close to 2000, it should then save it in the database table with a common ID (to fetch for future query). Once it saved in the database, it then continues to fetch the next row and sum up to <= 2000. This process is required to do till the last row.
I tried few while loops and for and for each loops but cant get my head around.
screenshot:
PHP code
<?php
$total = 0;
$getValue = 0;
$end = 2000;
do {
$start = $row_GenRunRS['SUM(WeightKgs)'] ;
$getValue = $start + $total;
echo $row_GenRunRS['SUM(WeightKgs)']. " + ". $total ." = " . $getValue . " <br>";
$total = $start + $total ;
echo "<br> <hr><br>";
// echo " Start ". $start. " <br>";
} while ($row_GenRunRS = mysql_fetch_assoc($GenRunRS));
echo "Total now = " .$total;
?>