php class Table var number function Table number this- number number f

 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
class Table {
var $number;
function Table($number) {
$this->number = $number;
}
function calculate(){
$nums = array('1', '2', '3', '4', '5', '6', '7', '8', '9', '10');
echo "<div class = 'wrapper'><table><tr>";
foreach ($nums as $key) {
echo "<tr>
<td>
$this->number x $key = ".($key*$this->number)."
</td>
</tr>";
}
echo "</tr></table></div>";
}
}
?>
<div class = "wrapper">
<a href="index.html">prev</a>
| Task 1 |
<a href="Task2.php">next</a><hr>
<form method="post">
<input type="text" name="number" placeholder="Your number..."/><br>
<input type="submit" class="btn" name="submit" value="Send"/>
</form>
<?php
if(isset($_POST["submit"]))
{
$n = intval($_POST["number"]);
if (empty($_POST["number"]))
{
echo "Enter number!";
}
else
{
$table = new Table($n);
$table->calculate();
}
}
?>
</div>
<style type="text/css">
.wrapper{
width: 200px;
margin: 0 auto;
text-align:center;
}
input{
margin-bottom: 10px;
width: 100%;
}
.btn{
width: 100%;
}
table{
width: 100%;
text-align: center;
}
</style>