Number Tables Using PHP

Hello

Just wrote a few Random PHP Programs creating Numbers Table 1 to 100. Remember in Nursery our Teachers made us write these numbers so many times in our Maths Notebook.

So Here comes a quick way to print the Numbers in Nice Colorful Tables.

Table_1.php

<html>

<head>
	<title>Number Table using PHP</title>

	<style type="text/css">
	td
	{
	height:50px; width:50px;
	}

	table,th,td
	{
	font-family:Arial; font-size:17px;
	color:navy; font-weight: normal;
	border: 2px solid red;
	text-align: center;
	border-collapse:collapse;
	}

	th
	{
	font-family:Arial; font-size:25px;
	color:white; font-weight: bold; font-style:italic;
	text-align: center;
	}

</style>
</head>

<body>
<?php
echo "<table border=\"1\" align=\"center\" bgcolor=\"red\">";
echo "<tr> <th colspan=\"10\"> Number Table </th> </tr>";

//For loop will iterate for 10 times to create 10 rows.
for($i=1;$i<=10;$i++)
{
	echo "<tr align=\"center\">";

	for($j=9;$j>=0;$j--)
	{
			echo "<td   bgcolor=\"white\">";
			$t=10*($i);
			$t1=$t-$j;
			echo $t1;
			echo "</td>";

	}//for loop ends
	echo "</tr>";

	}//outer for end.
echo "</table>";

?>

</body>
</html>

Snapshot of the o/p

Number Table 1 to 100

Table_2.php


<html>

<head>
	<title>Number Table using PHP</title>

	<style type="text/css">

	td
	{
	height:50px; width:50px;
	}

	table,th,td
	{
	font-family:Arial; font-size:17px;
	color:navy; font-weight: normal;
	border: 2px solid red;
	text-align: center;
	border-collapse:collapse;
	}

	th
	{
	font-family:Arial; font-size:25px;
	color:WHITE; font-weight: bold; font-style:italic;
	text-align: center;
	}

</style>
</head>

<body>
<?php
echo "<table border=\"1\" align=\"center\" bgcolor=\"red\">";
echo "<tr> <th colspan=\"10\"> Number Table </th> </tr>";

//For loop will iterate for 5 times to create 10 rows.
for($i=1;$i<=10;$i=$i+2)
{
	echo "<tr align=\"center\">";

	for($j=9;$j>=0;$j--)
	{
			echo "<td   bgcolor=\"white\">";
			$t=10*($i);
			$t1=$t-$j;
			echo $t1;
			echo "</td>";

	}//for loop ends
	echo "</tr>";

	echo "<tr align=\"center\">";

	for($j=1;$j<=10;$j++)
	{
			echo "<td   bgcolor=\"pink\">";
			$t=10*($i);
			$t1=$t+$j;
			echo $t1;
			echo "</td>";

	}//for loop ends
	echo "</tr>";
}//outer for end.
echo "</table>";

?>

</body>
</html>

Snapshot of the o/p

Number Table 1 to 100 with Different colored rows

Table_3.php

<html>

<head>
	<title>Number Table using PHP</title>

	<style type="text/css">

	td
	{
	height:50px; width:50px;
	}

	table,th,td
	{
	font-family:Arial; font-size:17px;
	color:navy; font-weight: normal;
	border: 2px solid red;
	text-align: center;
	border-collapse:collapse;
	}

	th
	{
	font-family:Arial; font-size:25px;
	color:WHITE; font-weight: bold; font-style:italic;
	text-align: center;
	}

</style>
</head>

<body>
<?php
echo "<table border=\"1\" align=\"center\" bgcolor=\"red\">";
echo "<tr> <th colspan=\"10\"> Number Table </th> </tr>";

//For loop will iterate for 5 times to create 10 rows.
for($i=1;$i<=10;$i=$i+2)
{
	echo "<tr align=\"center\">";

	for($j=9;$j>=0;$j--)
	{
		if(($j%2)==0)
			{
			echo "<td   bgcolor=\"white\">";
			}
		else
			{
			echo "<td bgcolor=\"pink\">";
			}
			$t=10*($i);
			$t1=$t-$j;
			echo $t1;
			echo "</td>";

	}//for loop ends
	echo "</tr>";

	echo "<tr align=\"center\">";

	for($j=1;$j<=10;$j++)
	{
		if(($j%2)==0)
			{
			echo "<td   bgcolor=\"pink\">";
			}
		else
			{
			echo "<td bgcolor=\"white\">";
			}
			$t=10*($i);
			$t1=$t+$j;
			echo $t1;
			echo "</td>";

	}//for loop ends
	echo "</tr>";
}//outer for end.
echo "</table>";

?>

</body>
</html>

Snapshot of the o/p

Number Table 1 to 100 with different cell colors

Table_4.php

<html>

<head>
	<title>Number Table using PHP</title>

	<style type="text/css">

	td
	{
	height:50px; width:50px;
	}

	table,th,td
	{
	font-family:Arial; font-size:17px;
	color:navy; font-weight: normal;
	border: 2px solid red;
	text-align: center;
	border-collapse:collapse;
	}

	th
	{
	font-family:Arial; font-size:25px;
	color:WHITE; font-weight: bold; font-style:italic;
	text-align: center;
	}

</style>
</head>

<body>
<?php
echo "<table border=\"1\" align=\"center\" bgcolor=\"red\">";
echo "<tr> <th colspan=\"10\"> Number Table </th> </tr>";

for($i=10;$i>=1;$i--)
	{
	echo "<tr align=\"center\">";
	//For loop creates rows of numbers in Descending order..100,99,98,...,91
	for($j=0;$j<10;$j++)
	{
		//For different color cells we have used if condition
		if(($j%2)==0)
			{
			echo "<td   bgcolor=\"white\">";
			}
		else
			{
			echo "<td bgcolor=\"pink\">";
			}
			$t=10*($i);
			$t1=$t-$j;
			echo $t1;
			echo "</td>";
	}
	//for loop ends
	echo "</tr>";

	}//outer for end.
echo "</table>";

?>

</body>
</html>

Snapshot of the o/p

Number Table 1 to 100 in Descending Order

Chess Board Using PHP

Here comes a very cool Chess Board using PHP. Anybody try and make a Chess Application.

For loops are used to create this application.There is an outer for loop determining the rows.
Inner for loops are used to create the coulmns.

Explaination-Iteration refering to outer for loop.
In the 1st iteration two rows are created from the top. The first row starts from white and the 2nd row from black.
In the 2nd iteration the 3rd row is created starting from white and the 4th row from black.
The same process continues till the 4th iteration.

<html>

<head>
	<title>Chess Board using PHP</title>

	<style type="text/css">
	td
	{
	height:75px; width:75px;
	}

	table
	{
	border: 4px solid black;
	border-collapse:collapse;
	}

	h2
	{
	font-family:Arial; font-size:25px;
	color:royalblue; font-weight: bold;
	text-align: center;
	}

</style>
</head>

<body>
	<h2>Chess Board</h2>
	<!--A chessboard is the type of checkerboard used in the board game chess,
	and consists of 64 squares (eight rows and eight columns) arranged in two alternating
	colors black and white-->

<?php
echo "<table border=\"1\" align=\"center\">";

//During 1 iteration 2 top rows are created.
//For loop will iterate 4 times creating 8 rows.
for($i=4;$i>=1;$i--)
{
	//First Row
	echo "<tr align=\"center\">";
	//For loop creates 1st row starting from white
	for($j=0;$j<8;$j++)
	{
		if(($j%2)==0)
			{
				$color = "white";
			}
		else
			{
				$color = "black";

			}
			echo "<td bgcolor =\"$color\"></td>";
	}//for loop ends
	echo "</tr>";

	//Second Row starting with black
	echo "<tr align=\"center\">";

	//For loop creates 2nd row starting from black
	for($j=7;$j>=0;$j--)
	{
		if(($j%2)==0)
			{
				$color = "white";
			}
		else
			{
				$color = "black";
			}
			echo "<td bgcolor =\"$color\"></td>";
		}//for loop ends
	echo "</tr>";

//This way also we can create the rows
/*

 echo "<tr align=\"center\">";

	//For loop creates 2nd row starting from black
	for($j=0;$j<8;$j++)
		{
		if(($j%2)==0)
			{
			echo "<td bgcolor=\"black\">";
			}
		else
			{
			echo "<td bgcolor=\"white\">";
			}
			echo "</td>";
		}//for loop ends
	echo "</tr>";
*/

}//outer for ends.
echo "</table>";

?>
<br /><br />
</body>
</html>

Snapshot of the o/p

ChessBoard_in_PHP

Chess Board using PHP

Enjoy and Keep Programming. :D

Multiplication Table in Java

This is a very basic program But for a beginner it is worth trying.

And it also makes us aware about the power of for loop which can repeat so many times within a second.

public class MulTable
{
	public static void main(String[] args)
	{
		int i;
		int num = 9;
		for(i=1; i<=10; i++)
		{
			System.out.println(num+ " * " +i+ " = "+num * i);
		}
	}
}

Snapshot of the o/p