note 19947 added to language.types.array
| From: | sssolomon at hotmail dot com | Date: | Sat, 16 Mar 2002 02:26:34 +0000 |
| Subject: | note 19947 added to language.types.array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-27849@lists.php.net to get a copy of this message | ||
For forms I use "${$foo}" thing:
if ($action=="")
{
echo "<form method=\"post\" action=\"form.php\">";
$amount=3; //(or input on another form)
For ($loopVar=0; $loopVar<$amount; $loopVar++)
{
printf ("Input number %s <input type=\"text\" name=\"%s\">",
($loopVar+1),$loopVar);
}
echo "<input type=\"hidden\" name=\"action\"
value=\"submit\"><input type=\"hidden\" name=\"amount\"
value=\"$amount\"><input type=\"submit\" name=\"submit\"
value=\"submit\"></form>";
}elseif ($action=="submit")
{
for ($loopVar=0; $loopVar<$amount; $loopVar++)
{
$input[$loopVar]=${$loopVar};
}
}
I like this way best. You can also have multiple inputs. Just for the second "printf()"
use:
printf ("Input number %s <input type=\"text\" name=\"%s\">",
($loopVar+1),($loopVar+1)*1000000);
and for the loop change ${$loopVar} to ${$((loopVar/1000000)-1)};
That is so that you don't have 2 fields the same "name=" unless the person asks to
input more than 1 million numbers...
--
http://www.php.net/manual/en/language.types.array.php
http://master.php.net/manage/user-notes.php?action=edit+19947
http://master.php.net/manage/user-notes.php?action=delete+19947
http://master.php.net/manage/user-notes.php?action=reject+19947