5 x 1 = 5
5 x 2 = 10
and so on
So lets start our tutorials. Look at below code
1 2 3 4 5 6 |
<?php $num = 5; for($i=1;$i<=10;$i++){ echo $num . ' X ' . $i . ' = ' . $i*$num . '<br>' ; } ?> |
You can see the code is very very simple. You just store value in $num variable and then with for() loop first you echo $num variable then with . you separate next value then print x then print $i and at last we multiply $i and $num.
On the above code you have to change $num in coding view but the code that I am giving below will get value from user and then print the table of given value. It involves some html tags but logic is same as above.
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 34 35 36 37 38 39 40 41 42 |
<html> <head> <title> School Days Table </title> </head> <body> <form action="index.php" method="post"> <input type="text" name="num" /> <input type="submit" value="Show Table" /> </form> <table> </table> <?php if(isset($_POST['num'])){ $num = $_POST['num']; ?> <table border="1" width="120"> <tr> <td colspan="5"> Table of <?php echo $num; ?></td> </tr> <?php for($i=1;$i<=10;$i++){ ?> <tr> <td> <?php echo $num; ?></td> <td> x </td> <td> <?php echo $i; ?></td> <td> = </td> <td> <?php echo $i*$num; ?></td> </tr> <?php } ?> </table> <?php } else { echo ""; } ?> </body> </html> |
good tutorial
Thanks Mr. Waseem