Advertisement
a_mcruer

php1

Feb 4th, 2013
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.71 KB | None | 0 0
  1. <?php
  2.  
  3.    // TODO: Implement meh
  4.  
  5.         if(isset($_POST))
  6.         {
  7.                 $rows=$_POST['rows'];
  8.                 $columns=$_POST['columns'];
  9.                 $operations=$_POST['operation'];
  10.                 $counterColumns = 0;
  11.                 $counterRows = 0;
  12.  
  13.  
  14.                 if(is_numeric($rows) == false || $rows<0)
  15.                 {
  16.                         echo "Invalid row input.";
  17.                 }
  18.  
  19.  
  20.         else
  21.                 {
  22.                         if($operations == 'multiplication')
  23.                         {
  24.                                 echo "This is the ".$columns." x ".$rows." multiplication table.";
  25.                         }
  26.                         else
  27.                         {
  28.                                 echo "This is the ".$columns." + ".$rows." addition table.";
  29.                         }
  30.  
  31.                         echo "<table border=\"1\">";
  32.                         //for loop for table rows
  33.  
  34.                         for($counterRows; $counterRows <= $rows; $counterRows++)
  35.                         {
  36.                                 echo "<tr>";
  37.                                 for($counterColumns = 0; $counterColumns <= $columns; $counterColumns++)
  38.                                 {
  39.                                         echo "<td>";
  40.  
  41.                                         if($operations == 'multiplication')
  42.                                         {
  43.                                                 if($counterRows == 0)
  44.                                                 {
  45.                                                         echo $counterColumns;
  46.                                                 }
  47.                                                 else if($counterColumns == 0)
  48.                                                 {
  49.                                                         echo $counterRows;
  50.                                                 }
  51.                                                 else
  52.                                                 {
  53.                                                         $calc= $counterRows * $counterColumns;
  54.                                                 }
  55.                                         }
  56.                                         else
  57.                                         {
  58.                                                 $calc=$counterRows + $counterColumns;
  59.                                         }
  60.  
  61.                                         echo(htmlspecialchars($calc));
  62.                                         echo "</td>";
  63.                                 }
  64.                                 echo "</tr>";
  65.  
  66.  
  67.                         }
  68.                 echo "</table>";
  69.                 }
  70.         }
  71. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement