Multiplication Table of a number using PHP

2 min read

A multiplication table, also known as a times table or multiplication chart, is a mathematical reference used to display the multiplication products of numbers in a systematic and organized way. It is a helpful tool for learning and practicing multiplication facts, especially for students who are just beginning to understand multiplication.

Multiplication Table using PHP

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.1/css/bootstrap.min.css"/>
<style>
  .box{
    padding: 40px;
    background: #ffb077;
  }
</style>
<div class="container mt-5">
  <div class="row justify-content-center">
    <div class="col-6">
      <div class="box">
        <form action="" method="get">
          <div class="row">
            <div class="col-5">
              Number
            </div>
            <div class="col-7">
              <input type="text" name="number" class="form-control">
            </div>
          </div>
        </form>
      </div>
    </div>
    <div class="col-6">
      <?php if(isset($_GET['number'])){?>
        <?php $number = $_GET['number'];?>
        <div class="box">
          <h3>Multiplication Table of <?php echo $number;?></h3>
          <table class="mt-3 table table-bordered table-striped">
            <tbody>
              <?php for($i=1;$i<=10;$i++){?>
                <tr>
                  <td class="text-center">
                    <?php echo $number;?> * <?php echo $i;?> = <?php echo $number*$i;?>
                  </td>
                </tr>
              <?php } ?>
            </tbody>
          </table>
        </div>
      <?php } ?>
    </div>
  </div>
</div>

Follow this video for complete guidance :

This code creates a simple HTML form where users can enter a number. Upon submitting the form, the PHP code generates a multiplication table for that number and displays it in a basic HTML table structure.

Recommended For You

About the Author: Ritesh Ghimire