note 50451 added to control-structures.for
| From: | BenitoJohotoson at osu1 dot php dot net | Date: | Mon, 28 Feb 2005 22:19:29 +0000 |
| Subject: | note 50451 added to control-structures.for | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-85694@lists.php.net to get a copy of this message | ||
<?
/////////////////////////////////////////////////////////////////////
/*This script is for incrimenting or decrementing between page loads.
The problem occurs when we try to pass a php variable value after
a POST submission. All PHP variables are dropped upon reload of the
page and only that data which POST passes can move between sessions:
exluding cookies that is.
We work around this by using a counter and incrimenting the POST
name with our PHP counter variable. This is kind of like leaving
a note for ourselves. When the page reloads the first thing we
do is use a for loop to check the POST variable's value. When
we find it we initialize our PHP variables based upon this.*/
/////////////////////////////////////////////////////////////////////
for($a=0; $a<100; $a++)
{
if($_POST['inc' . $a])
{
$i=$a+1;
}
if($_POST['dec' .$a])
{
$i=$a-1;
}
}
if($i<1)
{
$i=0;
}
?>
<form method="post" action="incl.php">
Number of Items<input value=<?print $i?> type="Text"
name="title"><br>
<TR<td><td><input type="Submit" name="inc<?print $i;?>"
value="Add an item <? print $i;?>"><br>
<TR<td><td><input type="Submit" name="dec<?print $i;?>"
value="Remove an item <? print $i;?>"><br>
----
Manual Page -- http://www.php.net/manual/en/control-structures.for.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+50451
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+50451&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+50451&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+50451&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+50451&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+50451&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+50451&report=yes
Search -- http://master.php.net/manage/user-notes.php