Hey hows it going people.....
I am trying to make a multiplication table...
Basically this how i have setup my files:
index.php
^^^^^^^contains a form where the user enters a number to define the size of the table he/she wnats.
multi.php
^^^^^^^collects the feild "size" from the index.php page and creates a multiplication table out of the size that is inputed by the user.
So whatever the user inputs as the number, i want to display a page by that size. See Example below.
User inputs 4 as number for the size.
- 1 2 3 4
1 1 2 3 4
2 2 4 6 8
3 3 6 9 12
4 4 8 12 16
Below is the source code i manged to write up. To my knowledge at least.
index.php
========
<form action="multi.php" method="POST">
<strong><font size="2"><font face="Geneva, Arial, Helvetica, sans-serif">Name:
<input type="text" name="name" />
<br>
Age:
<input type="text" name="age" />
<br>
Enter Table Size:
<input type="text" name="size" />
</font></font></strong><br>
<input type="submit" />
</form>
multi.php
======
Welcome <?php echo $_POST["name"]; ?>.<br />
You are <?php echo $_POST["age"]; ?> years old!<br />
Size of table <?php echo $_POST["size"]; ?>
<p> </p>
<?php
for ($i=1; $i<= $_POST["size"]; $i++)
{
echo $i * $_POST["size"] . "<br/>";
}
?>
Lol. As you can see i only managed to do the basic math part of it. Its just generating the table. Iam totally clued out at.....
If anyone can give me some pointers, i will highly appreciate it. Thx !
?>
table (multiplication) !
Moderator: General Moderators
ok, you have 2d table, so basically you need 2 nested loops. Such as:
Code: Select all
for ($j=1; $j<= $_POST["size"]; $j++){
for ($i=1; $i<= $_POST["size"]; $i++)
{
echo $i * $j . " ";
}
echo "\n";
}