I'm getting values from a form and trying to multiply them with values on the left hand side incremented in 5s. I added in a picture of the results too.
Code:
<?php
if ($_SERVER["REQUEST_METHOD"] == "GET") {
$costOne = trim($_GET["c1"]);
$costTwo = trim($_GET["c2"]);
$costThree = trim($_GET["c3"]);
$costFour = trim($_GET["c4"]);
$costFive = trim($_GET["c5"]);
$minimum = trim($_GET["min"]);
$maximum = trim($_GET["max"]);
}
echo '<table>';
echo '<tr>';
echo '<th>Cost per person<br>Party size</th>';
echo "<th>$costOne</th>";
echo "<th>$costTwo</th>";
echo "<th>$costThree</th>";
echo "<th>$costFour</th>";
echo "<th>$costFive</th>";
echo '</tr>';
for ($col=$minimum; $col <= $maximum; $col =5) {
echo "<tr>";
echo "<td>$col</td>";
echo "<td>$col*$costOne</td>";
echo "<td>$col*$costTwo</td>";
echo "<td>$col*$costThree</td>";
echo "<td>$col*$costFour</td>";
echo "<td>$col*$costFive</td>";
echo "</tr>";
}
echo '</table>';
?>
CodePudding user response:
Try this:
for ($col=$minimum; $col <= $maximum; $col =5) {
echo "<tr>";
echo "<td>" .$col. "</td>";
echo "<td>" .$col*$costOne. "</td>";
echo "<td>" .$col*$costTwo. "</td>";
echo "<td>" .$col*$costThree. "</td>";
echo "<td>" .$col*$costFour. "</td>";
echo "<td>" .$col*$costFive. "</td>";
echo "</tr>";
}