Multiplication Table

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.

<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

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

Sorry for that :smiley:

Nice! :slight_smile:
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.

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

Cheers
Ramanakumar

Sponsor our Newsletter | Privacy Policy | Terms of Service