PHP - Times Table Chart - Computer Generated
From Global Programming Syntax
Sometimes you may need to lookup a few sums on a times table chart but can't find a large enought chart. Well with two loops it is possible to make a chart as big you want. All you need to do is reset the variable $size to change the size of the chart. The script is as follows:
$size=32;
echo "<table border=1 cellpadding=2 cellspacing=0>";
for ($x=1;$x<=$size;$x++) {
echo "<tr>";
for ($y=1;$y<=$size;$y++) {
$var=$x*$y;
if ($x==1 && $y==1) {
echo "<td bgcolor=#CCCCCC align='center' valign='middle' width=26 height=28><b><font face='arial'>X</font></b></td>";
} else if ($x==1 || $y==1) {
echo "<td bgcolor=#CCCCCC align='center' valign='middle' width=26 height=28><b>".$var."</b></td>";
} else {
echo "<td align='center' valign='middle' width=26 height=28>".$var."</td>";
}
unset($var);
}
echo "</tr>";
}
echo "</table>";
Also if you are looking for a computer generated times table chart that shows the one times table then the following will do the job:
$size=32;
echo "<table border=1 cellpadding=2 cellspacing=0>";
$varx=1;
$vary=1;
for ($x=1;$x<=$size;$x++) {
echo "<tr>";
for ($y=1;$y<=$size;$y++) {
$var=$x*$y;
if ($x==1 && $y==1 && $varx!==0 && $vary==1) {
echo "<td bgcolor=#CCCCCC align='center' valign='middle' width=26 height=28><b><font face='arial'>X</font></b></td>";
} else if (($x==1 || $y==1) && ($varx!==0 || $vary==1)) {
echo "<td bgcolor=#CCCCCC align='center' valign='middle' width=26 height=28><b>".$var."</b></td>";
} else {
echo "<td align='center' valign='middle' width=26 height=28>".$var."</td>";
}
if ($y==1 && $vary==1) {
$vary=0;
$y=0;
}
unset($var);
}
$vary=1;
echo "</tr>";
if ($x==1 && $varx==1) {
$varx=0;
$x=0;
}
}
echo "</table>";
