Writing out a Table

Create Multiplication table. Using a loop within a for loop, create a row and a column variable. Set column test to 12 to stop printing columns at 12.

Core PHP Programming page 74-75.

BEGIN PHP output

123456789101112
24681012141618202224
369121518212427303336
4812162024283236404448
51015202530354045505560
61218243036424854606672
71421283542495663707784
81624324048566472808896
918273645546372819099108
102030405060708090100110120
112233445566778899110121132
1224364860728496108120132144


END PHP output

<?php

/* Define class for tracking users */
class user
{
  /*
  ** Make a multiplication table
  */
  
  print("<table border=\"1\">\n");  // start table
  for($row=1; $row <= 12; $row++)
  {
    print("<tr>\n");  // start row
    
    //do each column
    for($col=1; $col <= 12; $col++)
    {
        print("<td>");
        print($row * $col);
        print("</td>");
      }
      print("</tr>\n");  // end row
    }
    print("</table>\n");

     
?>

Back to Bill's PHP