<html> <head> <title>Create Table Dynamically</title> <style> </style> </head> <body> <form method="post" action ="main.php"> <table border="1" width="350px"> <tr> <td>Enter number of Rows</td> <td><input type="text" name="rows"/></td> </tr> <tr> <td>Enter number of Columns</td> <td><input type="text" name="columns"/></td> </tr> <tr> <td colspan="2" align="center"> <input type="submit" value="Create Table" name="create"/> </td> </tr> </table> </form> <span style="color:red"></span> <?php if(isset($_REQUEST['create'])) { ?> <span class="comments"> <?php $row=$_REQUEST['rows']; ?> <span class="comments"></span> <?php $col=$_REQUEST['columns']; ?> <span class="comments"> </span> <?php echo "<table border='1' width='350px'>"; for($i=1;$i<=$row;$i++) { ?> <span class="comments"></span> <?php echo "<tr>"; for($j=1;$j<=$col;$j++) { ?> <span class="comments"></span> <?php echo "<td>row".$i."col".$j."</td>"; } ?> <span class="comments"></span> <?php echo "</tr>"; } ?> <span class="comments"></span> <?php echo "</table>"; } ?> <span style="color:red"></span> </body> </html>
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy. Accept Learn more