I made a PHP function that creates the html code for making a table based on the user's choice of column and row number.
So the user opens an HTML page, enters the number of columns and rows, and the PHP generates the HTML code for that table.
However, I'd like it so that instead of creating the code for the table, the PHP would just create an HTML table.
How can I achieve this?
HTML File:
<html>
<form action="tableCode.php" method="get" />
<p> Enter the number of rows
<input type="text" name="row"/>
and the number of columns:
<input type="text" name="col"/>
<input type="submit" name="Submit" value="Submit" />
</p>
</form>
</body>
</html>
PHP File
<?php
$row = $_GET['row'];
$col = $_GET['col'];
function makeTable($row,$col)
{
$begin = "<html> <br> <head> <br> <style> <br> table, th, td {border: 1px solid black;}
<br> </style> <br> </head> <br> <body> <br> <table style=width:100%> <br>";
for($i = 0; $i < $row; $i++)
{
$begin .= "<tr> <br>";
for($j = 0; $j < $col; $j++)
{
$begin .= "<td> Enter column data here </td> <br>";
}
$begin .= "</tr> <br>";
}
$begin .= "</table> <br> </body> <br> </html>";
echo $begin;
}
makeTable($row,$col);
?>
String returned when calling makeTable(2,2)
<html>
<head>
<style>
table, th, td {border: 1px solid black;}
</style>
</head>
<body>
<table style=width:100%>
<tr>
<td> Enter column data here </td>
<td> Enter column data here </td>
</tr>
<tr>
<td> Enter column data here </td>
<td> Enter column data here </td>
</tr>
</table>
</body>
</html>