By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,650 Members | 812 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,650 IT Pros & Developers. It's quick & easy.

defining the variable

P: 56
hello everyone,
This is my code:

if($i==1)
{
echo "first time";
$i++;
echo '<script language="javascript">document.location="'.basenam e($_SERVER['PHP_SELF']).'";</script>'; //it reloads my page
}
if($i==2)
{
echo "second time";
$i++;
echo '<script language="javascript">document.location="'.basenam e($_SERVER['PHP_SELF']).'";</script>';
}
if($i==3)
{
echo "third time";
$i++;
echo '<script language="javascript">document.location="'.basenam e($_SERVER['PHP_SELF']).'";</script>'; //it reloads my page
}


i want that how can i maintain the incremented value of variable $i after each page reload.so that i can execute specific code in if statement.

thanks in advance...
Jan 8 '08 #1
Share this Question
Share on Google+
1 Reply


PareshRathod
P: 28
Hello Sejal...

Yah i am the same Paresh...

When your page get's reload the value of variable initialize..
To maintain the value of variable, you have to store it in session and when your page get loaded retrieve it from session like below:

if (isset($_SESSION['i']))$i=$_SESSION['i'];
Then do your as usual coding...
don't forget to add add session_start() if it is not there... :)

Have a nice time..
Say thanks if it helps..

Paresh

hello everyone,
This is my code:

if($i==1)
{
echo "first time";
$i++;
echo '<script language="javascript">document.location="'.basenam e($_SERVER['PHP_SELF']).'";</script>'; //it reloads my page
}
if($i==2)
{
echo "second time";
$i++;
echo '<script language="javascript">document.location="'.basenam e($_SERVER['PHP_SELF']).'";</script>';
}
if($i==3)
{
echo "third time";
$i++;
echo '<script language="javascript">document.location="'.basenam e($_SERVER['PHP_SELF']).'";</script>'; //it reloads my page
}


i want that how can i maintain the incremented value of variable $i after each page reload.so that i can execute specific code in if statement.

thanks in advance...
Jan 8 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.