Creating Colorful Table using HTML and PHP – Programs for Beginners

table using html and php

Creating Table using HTML and PHP

Here’s another PHP program for Beginners on Programmingy. Are you ready to learn how to create a colorful table using HTML and PHP. Here you have to create a program – to take 3 user inputs. One: Number of rows, Another: Number of Columns and last you have to accept background colour for the table. Then Create a table according to given data by user and print each cell number of table in each cell.

First File – a.php

table using html and php

Here is just some basic HTML coding. Make a form, with 3 textboxes and 1 submit button. We will take Number of rows, number of columns and color of the table from user. We will use ‘GET’ Method to send value to our PHP file.

<head>PHP Programs</head>
<form name=”frm1″ method=”get” action=”rowcol.php”>
<input type=”text” placeholder=”Enter Number of rows” name=”row”>
<input type=”text” placeholder=”Enter Number of cols” name=”col”>

<input type=”text” placeholder=”background color ” name=”clr”>
<input type=”submit”>


Table Using HTML and PHP: Second File

table using html and php

In our first file, we simply made a form to take user inputs. Now we have to create a table using HTML and PHP here. Recieve all 3 inputs and store it in $row, $col, and $clr variables. Make another variable $cell for keeping the count of cell numbers (Make sure you initialize it with 1).

After all that, just start looping for making table. One thing you should know here is: How to Use HTML in PHP. To use HTML tags you simply use echo ” <TAG_NAME> “. For example to use new-line-tag (that is <BR>), all you have to do is write: echo “<BR>”;


echo “<table border=1 style=background-color:$clr>”;
echo “<tr>”;
echo “<td>$cell</td>”;
echo “</tr>”;

echo “</table>”;

LEARN: Factorial Program by Taking Input in PHP 

Hope you learnt to create Table using HTML and PHP from the article. If you want some specific program in PHP Programming do comment below and share your views about our article below. Keep Coding!



Please enter your comment!
Please enter your name here