I have an array of data that I’m getting from this form (form.php):
<?
include"connect.php";
$sql = "select * from tbsatpor ";
$qry = mysql_query($sql);
echo"<form name='submit' method='POST' action='proses.php'>";
$no = 1;
while ($data = mysql_fetch_array($qry)){
$nomor = $no++;
echo "<input type='text' name='kd_satpor[]' value='$data[kd_satpor]' >
<input type='text' name='kd_unor[]' value='$data[kd_unor]' >
<input type='text' name='buy[]' value=''><br>";
}
echo"<input type='submit' name='submit' value='submit'></form>";
?>
Here’s resultpage.php:
<?
echo "<table border='0' size=100%>
<tr><td>CODE</td><td>BUY</td><td>UNOR</td><td>TOTAL SUM</td></tr>";
for ($i=0; $i<count($_POST['buy']);$i++){
$_session[$i] = $_POST['kd_satpor'][$i];
$_session[$_POST['buy'][$i]] = $_POST['buy'][$i];
$_session[$_POST['kd_unor'][$i]] = $_POST['kd_unor'][$i];
$total[i] = $_session[$_POST['kd_unor'][$i]] * $_session[$_POST['buy'][$i]];
if($total[i]!=0){
echo "<tr><td>".$_session[$i]."</td><td>" .$_session[$_POST['buy'][$i]]." X
</td><td>".$_session[$_POST['kd_unor'][$i]]."=</td><td>".$total[i]."</td>
<td></tr>";
}
}
echo"</table>";
?>
The data array looks like this (the output of resultpage.php):
CODE | BUY | UNOR | SUM
+++++++++++++++++++++++++++++++
024K30 | 10000 | 2 | 20000 | => 10000 x 2 = 20000
024K31 | 2000 | 3 | 6000 | => 2000 x 3 = 6000
024K32 | 5000 | 3 | 15000 | => 5000 x 3 = 15000
TOTAL?
I want to create TOTAL SUM from the array and show the result from that code. How can I do that?
Also, use
$_SESSIONnot$_sessionif you intend to use the PHP session and don’t forget to run any POST data throughhtmlentities()before you echo it out onto a page.