PHP Classes

Multiplication Practice: Multiply and verify numbers taken from forms

Recommend this page to a friend!
  Info   View files Example   View files View files (3)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 83 All time: 10,036 This week: 206Up
Version License PHP version Categories
multiplication-pract 1.0The PHP License5PHP 5, Math
Description 

Author

This class can multiply and verify numbers taken from forms.

It takes an array with values taken from a submitted form that takes two numbers and a result of multiplication and another for the sum.

The class verifies if the multiplication and sum are correct.

Picture of Gary Fuller
Name: Gary Fuller <contact>
Classes: 1 package by
Country: United Kingdom
Age: ???
All time rank: 4437194 in United Kingdom
Week rank: 295 Up13 in United Kingdom Up

Example

<html>
  <head>
    <meta charset="UTF-8">
    <title></title>
  </head>
  <body>
<?php
// Clean up the post data and set it as the variable $post_data.
$post_data = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING);
// Include the class file.
require_once('class.multiplication.php');
// Define the numbers to use in the calculations.
$number_array = [0,1,2,3,4,5,6,7,8,9,10,11,12];
// Pick two random numbers for the sum.
$first_number = array_rand($number_array);
$second_number = array_rand($number_array);
// If an answer has been posted, check that it is correct.
if(isset($post_data)) {
   
// Instantiate the class passing in the post data as an argument.
   
$test = new randomMultiplicationChecker($post_data);
   
// Call the answerCheck method and create the variables $correct and $number_correct from what it returns.
   
list($correct, $number_correct, $question_number, $level_number) = $test->answerCheck();
} else {
   
$question_number = 1;
   
$level_number = 1;
   
$number_correct = 0;
}
?>

<?php
// If this is the first time the page has been loaded or the previous answer was correct,
// show the form and a new question.
if(!isset($post_data) || $correct === true): ?>
<h1>Level <?php echo $level_number; ?> : Question <?php echo $question_number; ?></h1>
<p>Input your answer and click submit before you run out of time...</p>
<p>What is <?php echo $first_number ?> x <?php echo $second_number ?>?</p>
    <form id="answer" method="post" action="<?php $_SERVER["PHP_SELF"]; ?>">
      <input type="text" name="sumAnswer">
      <input type="hidden" value="<?php echo $first_number ?>" name="firstNumber">
      <input type="hidden" value="<?php echo $second_number ?>" name="secondNumber">
      <input type="hidden" value="<?php echo $number_correct ?>" name="numberCorrect">
      <input type="hidden" value="<?php echo $question_number ?>" name="questionNumber">
      <input type="hidden" value="<?php echo $level_number ?>" name="levelNumber">
      <input type="submit">
    </form>
<?php else: ?>
<h1>Nice Try! You got <?php echo $number_correct; ?> correct!</h1>
<?php endif; ?>
</body>
</html>


Details

multiplication_practice

Very basic multiplication practice app for my kids


  Files folder image Files  
File Role Description
Plain text file class.multiplication.php Class Class source
Accessible without login Plain text file index.php Example Example script
Accessible without login Plain text file README.md Doc. Documentation

 Version Control Unique User Downloads Download Rankings  
 100%
Total:83
This week:0
All time:10,036
This week:206Up