Print Table of any Number using PHP
In this tutorial, we will learn how to print a mathematical table of any number using PHP. First, create an HTML form for input Number.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
<!DOCTYPE html> <html> <head> <title>Table of a Number</title> </head> <body> <table> <form name="table" method="post"> <tr> <td>Enter Number :</td> <td><input type="text" name="num" required></td> </tr> <tr> <td></td> <td><input type="submit" value="submit" name="submit" /></td> </tr> </form> </table> </body> </html> |
PHP logic for printing a table
1 2 3 4 5 6 7 8 9 10 11 12 |
?php if(isset($_POST['submit'])) { $num=$_POST['num']; define('NUM',$num); for($i=1 ; $i<=10 ; $i++) { echo $i*NUM; echo '<br>'; } } ?> |
Here is the full code is written for this tutorial:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
?php if(isset($_POST['submit'])) { $num=$_POST['num']; define('NUM',$num); for($i=1 ; $i<=10 ; $i++) { echo $i*NUM; echo '<br>'; } } ?> <!DOCTYPE html> <html> <head> <title>Table of a Number</title> </head> <body> <table> <form name="table" method="post"> <tr> <td>Enter Number :</td> <td><input type="text" name="num" required></td> </tr> <tr> <td></td> <td><input type="submit" value="submit" name="submit" /></td> </tr> </form> </table> </body> </html> |