I answered you on a different forum, but I spruced it up a little. (I was still bored)
[php]<?php
/* I would pull the form and table apart, by that I mean /
/ don’t try to do two things at once. I haven’t done /
/ any number validation and I’m sure this needs to be /
/ modified for I don’t know what exactly the initial /
/ HTML looked liked. */
if ( isset($_POST[‘submit’]) && $_POST[‘submit’] == “Generate” ) {
$numRows = $_POST[‘rows’];
$numCols = $_POST[‘columns’];
$operand = $_POST[‘operation’];
}
?>
Learning How to Multiply & Add
table {
border-collapse: collapse;
}
table, th, td {
border: 1px solid #2e2e2e;
padding: 5px;
}
<?php $columns = isset($numCols) ? $numCols : 10; ?>
<?php echo $columns . " Columns"; ?> |
<?php
for($x = 0; $x < $columns; $x++) {
echo '' . $x . ' | ' . "\n";
}
?>
<?php
$rows = isset($numRows) ? $numRows : 10;
for($x = 0; $x < $rows; $x++) {
echo "\n";
for($y = 0; $y < $columns; $y++) {
/* If operand isn't set yet, I set it to an addition default */
if ( isset($operand) && ($operand == "multiplication")) {
echo "" . $x . " X " . $y . " = " . ($x * $y) . " | \n";
} elseif ( isset($operand) && ($operand == "addition") ) {
echo "" . $x . " + " . $y . " = " . ($x + $y) . " | \n";
} else {
echo "" . $x . " + " . $y . " = " . ($x + $y) . " | \n";
}
}
echo "
\n";
}
?>
Number of Rows:
Number of Cols:
1
2
4
8
10
16
Operation
Multiplication
Addition
[/php]