Wednesday, December 21, 2016

A simple PHP Dynamic Multiplication Table

A simple PHP Dynamic Multiplication Table


A simple PHP Dynamic Multiplication Table

By Alexies Iglesia


Using PHP we can build a lot of great web applications and websites. With your knowledge in HTML, CSS, Javascript, jQuery and other web development tools, you can make almost everything you want.

Today Im going to give you a simple code on how to make a simple multiplication table using PHP. It has two pages. The first page will get the input from the user, while the second page will show the output.

I used this as an introductory lesson for my student at Mondriaan Aura College. But starting from now,  Ill gonna share some of my resources online for the benifits of a lot of beginners who wants to study this code. 

For those who want to download the file, download it here
1st PAGE ("page1.php")

Code: 
        <!DOCTYPE html>
        <html>
        <head>
         <title></title>
        </head>
        <body>
                <form action = "page2.php" method="POST">
                        X value<input name="x"type="number" /><br/>
                        y value<input name="y" type="number" /><br/>
                        <input type="submit" value="Generate">
                </form>
        </body>
        </html>


2nd PAGE ("page2.php")

Code: 
        <!DOCTYPE html>
        <html>
         <head>
         <title></title>
         </head>
         <body>
         <?php
         $x=$_POST[x];
         $y=$_POST[y];

         for ($i=1;$i<=$y;$i++){
         echo "<table border=1 ><tr ><td width=30px>".$i."</td>";
        for ($a=2,$b=1;$b<$x;$b++,$a++){
         echo "<td width=30px >".$a*$i."</td>";
        }
        echo "</tr></table>";
        }
        ?>
         </body>
        </html>




Available link for download