0
I must create a code that the user can enter the number of rows and columns a table should have, and this table should appear to the user. I try this code here, but the table does not appear with the rows and columns I typed:
<?php
echo '<form action="Q.php" method="post">Digite o número de linhas: <input type="text" name="linhas"><br>Digite o número de colunas: <input type="text" name="colunas"><br><input type="submit" value="Construir tabela"></form>';
$linhas = $_POST['linhas'];
$colunas = $_POST['colunas'];
$l = 0;
$c = 0;
echo '<table border="1" width="400px" height="300px">';
while($l <= $linhas){
$l++;
echo '<tr>';
while($c <= $colunas){
$c++;
echo '<th></th>';
}
echo '</tr>';
}
?>
Thank you for your reply
Your $c counter is not being restarted in the second row, so it just creates the first row columns... See my answer below with correction
– Guilherme Branco Stracini
What is the result of your code? Did you look at the source code to make sure that the table was not generated? By the way, to get the values in
$_POST
you should make sure that a POST request has been made for the file, what’s more, you need to restart the column counter to each row and end with the tag</table>
. The elementth
sets the table header, so it is expected that only the first row exists. In the others, use the elementtd
.– Woss