I've been at this for quite some time and just can't figure it out.I have a html table and have to find the total sum of the values in the $total/Sale Cost (last) row. Can anyone help me out or point me in the right direction.
Code below:
<?php
print ("<table border=1><tr><th>Sale Number</th><th>Item</th><th>Item Cost</th><th>Units Sold</th><th>Sale Cost</th></tr>");
for($x=0; $x<=20; $x=$x+1) {
/*
$sofa_total = 0;
$table_total = 0;
$chair_total = 0;
$box_total = 0;
$tablecloth_total = 0;
*/
$amount = rand(1,10);
$res = rand(1, 5);
$object = 0;
$total = $amount * $cost;
if ($res == 1) {
$cost = 235.00;
$item = "sofa";
}
elseif ($res == 2) {
$cost = 125.00;
$item = "table";
}
elseif ($res == 3) {
$cost = 25.99;
$item = "chair";
}
elseif ($res == 4) {
$cost = 15.25;
$item = "box";
}
elseif ($res == 5) {
$cost = 23.50;
$item = "tablecloth";
}
print ("<tr>");
print ("<td>" . $table[$x][0] = $x+1 . "</td>");
print ("<td>" . $table[$x][1] = $item . "</td>");
print ("<td>" . $table[$x][2] = $cost . "</td>");
print ("<td>" . $table[$x][3] = $amount . "</td>");
print ("<td>" . $table[$x][4] = $total . "</td>");
}
print ("</tr>");
if ($object==0) {
$sofa_total = $sofa_total + $amount;
} elseif ($object==1) {
$table_total = $table_total + $amount;
} elseif ($object==2) {
$chair_total = $chair_total + $amount;
} elseif ($object==3) {
$box_total = $box_total + $amount;
} elseif ($object==4) {
$tablecloth_total = $tablecloth_total + $amount;
}
print ("</table>");
?>