# Multiplication Table

**URL:** <https://www.phphelp.com/t/multiplication-table/14103>\
**Category:** Code Snippets\
**Created:** [August 11, 2011, 3:22am UTC](https://www.phphelp.com/t/multiplication-table/14103 "2011-08-11T03:22:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ramanakumar](https://www.phphelp.com/letter_avatar_proxy/v4/letter/r/2acd7d/32.png) [@Ramanakumar](https://www.phphelp.com/u/Ramanakumar)\
**Post date:** [August 11, 2011, 3:22am UTC](https://www.phphelp.com/t/multiplication-table/14103/1 "2011-08-11T03:22:29Z")

</div>

Hey everyone,  
Not sure how helpful this is, but this is a multiplication table creator. The user has to enter the number of rows and columns, and the table will be created automatically.

```auto
<HTML>
<HEAD>
 <TITLE>Multiplication Table <?php while(!empty($maxr) && !empty($maxc)) { print "of $maxr X $maxc";}?></TITLE>
</HEAD>
<BODY background = "bamboo.jpg" bgproperties = "fixed">
<?php include("navbar.php"); ?>
<font color = "black">
<form method="POST">
<table border = 0>
  <tr>
  <td><b>Number of Rows: </td><td><input type="text" size="20" name = 'nr'></td>
  </tr><tr>
  <td><b>Number of Columns: </td><td><input type="text" size="20" name = 'nc'></td>
  </tr><tr>
  <td></td><td><input type="submit" value="Submit"></td>
  </tr>
</table>
</form>
<hr size="1">
<?php

  $maxr = $_POST['nr'];
  $maxc = $_POST['nc'];
  if(!empty($maxr) && !empty($maxc)) {

  for($n=1; $n<=$maxr; $n++) {
     $rows[] = $n;

  }
  for($n=1; $n<=$maxc; $n++) {
     $columns[] = $n;
  }

  print "<table cellspacing = \"0\">";
  echo "<tr align = \"center\" bgcolor = \"dodgerblue\" height = \"15\">
        <td bgcolor = \"white\" height = \"5\">&nbsp</td>";
  foreach($rows as $val) {
    print "<td width = \"20\">$val</td>";
  }
  echo "</tr>";
  foreach($columns as $val) {
    print "<tr height = \"20\">
           <td bgcolor = \"dodgerblue\" width = \"20\">$val</td>";
    foreach($rows as $value) {
       $multi = $val * $value;
       print "<td width = \"20\"><center>$multi</center></td>";
    }
    print "</tr>";
  }
  }else{
  print "Please enter value for Columns and Rows!";
  }
 }
?>
</BODY>
</HTML>
```

Cheers

---

<div class="post-metadata">

**Author:** ![Ramanakumar](https://www.phphelp.com/letter_avatar_proxy/v4/letter/r/2acd7d/32.png) [@Ramanakumar](https://www.phphelp.com/u/Ramanakumar)\
**Post date:** [August 11, 2011, 3:24am UTC](https://www.phphelp.com/t/multiplication-table/14103/2 "2011-08-11T03:24:20Z")

</div>

Hi…  
seems like there’s a small mistake. I forgot to remove the include(“navbar.php”) line from the script.

Sorry for that 😃

---

<div class="post-metadata">

**Author:** ![Naxirus](https://www.phphelp.com/user_avatar/www.phphelp.com/naxirus/32/406_2.png) [@Naxirus](https://www.phphelp.com/u/Naxirus)\
**Post date:** [August 22, 2011, 7:14pm UTC](https://www.phphelp.com/t/multiplication-table/14103/3 "2011-08-22T19:14:18Z")

</div>

Nice! 🙂  
I can’t imagine what this would be used for, but its well done at any rate.

Two things though:

1. You appear to have an extra ‘}’ at the end, which causes an error for me. Removing it made it function perfectly.
2. You should add a border around each for readability.

---

<div class="post-metadata">

**Author:** ![Ramanakumar](https://www.phphelp.com/letter_avatar_proxy/v4/letter/r/2acd7d/32.png) [@Ramanakumar](https://www.phphelp.com/u/Ramanakumar)\
**Post date:** [August 23, 2011, 5:49am UTC](https://www.phphelp.com/t/multiplication-table/14103/4 "2011-08-23T05:49:03Z")

</div>

Hey…  
thanks for the comments Naxirus… i’ll develop it…

Cheers  
Ramanakumar
