In: Computer Science
in PHP/HTML
PHP File :rowsCols.php
<!-- PHP Functionality -->
<?php
if(isset($_POST['btnRowsCols']))
{
//number of rows entered by user
$rows=$_POST['txtRows'];
//number of columns entered by user
$cols=$_POST['txtColumns'];
//declaring variable to store table
$htmlTable="<table border=1>";
//using for loop
//this for loop is used for number of rows
for($i=1;$i<=$rows;$i++)
{
$htmlTable= $htmlTable."<tr>";//creating row
//this for loop is used for number of columns
for($j=1;$j<=$cols;$j++)
{
//creating cell
$htmlTable=$htmlTable."<td>R".$i." C".$j."</td>";
}
$htmlTable=$htmlTable."</tr>";//close row
}
//closing of the table
$htmlTable=$htmlTable."</table>";
//display table on the web page
echo $htmlTable;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<!-- title for web page -->
<title>PHP Table</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<form action="rowsCols.php" method="post">
Enter number of rows :
<!-- textbox for number of rows -->
<input type="text" name="txtRows"/>
<br><br>
Enter number of columns/cells :
<!-- textbox for number of columns/cells -->
<input type="text" name="txtColumns"/>
<br><br>
<!-- button to submit form -->
<input type="submit" name="btnRowsCols"/>
</form>
</body>
</html>
======================================
Screen asking rows and columns :
Screen showing table :