PHP - Simple Multiplication Table
Submitted by razormist on Saturday, March 23, 2019 - 21:22.
In this tutorial we will create a Simple Multiplication Table using PHP. This program can display a multiplication table when the user enter a multiplier in the input text box. This simple code use a arithmetic function to multiply a couple of digit in order to achieve this table multiplier. This is a user-friendly kind of program feel free to modify it.
We will be using PHP as a scripting language that is used primarily on any webserver including xamp, wamp, etc. It describe as an advance technology that manage both server and control-block of your machine.
There you have it we successfully created Simple Multiplication Table using PHP. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!
Getting Started:
First you have to download & install XAMPP or any local server that run PHP scripts. Here's the link for XAMPP server https://www.apachefriends.org/index.html. And, this is the link for the bootstrap that i used for the layout design https://getbootstrap.com/.Creating The Interface
This is where we will create a simple form for our application. To create the forms simply copy and write it into your text editor, then save it as index.php.- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1"/>
- <link rel="stylesheet" type="text/css" href="css/bootstrap.css"/>
- </head>
- <body>
- <nav class="navbar navbar-default">
- <div class="container-fluid">
- <a class="navbar-brand" href="https://sourcecodester.com">Sourcecodester</a>
- </div>
- </nav>
- <div class="col-md-3"></div>
- <div class="col-md-6 well">
- <h3 class="text-primary">PHP - Simple Multiplication Table</h3>
- <hr style="border-top:1px dotted #ccc;"/>
- <form method="POST" action="">
- <div class="form-inline">
- <label>Enter a number:</label>
- <input type="number" class="form-control" min="0" max="10" name="digit" required="required"/>
- <button class="btn btn-primary" name="calculate">Calculate</button>
- </div>
- </form>
- <br /><br />
- <?php include 'calculate.php'?>
- </div>
- </body>
- </html>
Creating the Main Function
This code contains the main function of the application. This code will display a multiplication when the user enter data on the form. To make this just copy and write these block of codes below inside the text editor, then save it as calculate.php- <?php
- ?>
- <table class="table table-bordered">
- <?php
- for($i = 1; $i <= $_POST['digit']; $i++) {
- echo "<tr>";
- for($j = 1; $j <= 10; $j++){
- echo"<td>".$i*$j."</td>";
- }
- echo"</tr>";
- }
- ?>
- </table>
- <?php
- }
- ?>
Comments
Add new comment
- Add new comment
- 1413 views