go****@charliefortune.com wrote (in part):
I would like to print a table, using a while loop to insert as many
blank text fields as players specified by the user. How do I put html
inside a php loop.
This is what I have....
<body>
<form name="results" method="post">
Number of players:<input type ="textarea" name="number_players">
<input name="Submit" type="submit"></form>
<?php
$x=0;
while ($x<$number_players){
print ("Place : $x<br>");
$variable ="<input type="textarea" name=$x>";
print($variable);
$x++;
}
</body>
You almost have it right. Here's one way of doing what you want.
<?
$tmp = array();
$tmp[] = '<form action="' . $_SERVER['PHP_SELF'] . '" name="results"
method="post">';
$tmpv = (isset($_POST['number_of_players']))?' value="' .
$_POST['number_of_players'] . '"':'';
$tmp[] = 'Number of players: <input type="text"
name="number_of_players"' . $tmpv . '>';
if (isset($_POST['number_of_players']))
for ($i=0;$i<$_POST['number_of_players'];$i++)
$tmp[] = 'Place ' . $i . ': <input type="text" name="place[' .
$i . ']">';
$tmp[] = '<input type="submit" name="submit" value="Submit">';
echo implode("<br>\n",$tmp)."\n";
?>
Some explanation.
The first time a user brings up the form, just input box labeled
"Number of players" is displayed. When the user fills it in and presses
"submit", the form is redisplayed with the appropriate number of input
boxes.
More code is needed for this form to do anything else and I have done
no error checking, such as making sure that the input is really a
number.
Ken