Jump to content

[SOLVED] Next/Back buttons


DannyM

Recommended Posts

Hello once more!

I've found a strange glitch with my forward/backward buttons. When you click forward, everything works fine as it goes to the next value within the array. However, if you hit back, the variable $_SESSION['current'] will increase by one before it begins to go down again. The same is true if you click back a few times, then click forward. The $_SESSION['current'] will decrease once before it begins to increase again. How would one prevent this?

 

//FORWARD
if(isset($_POST["next"]))
{
if($_SESSION['current'] >= $_SESSION['pagenum'])
{
$_SESSION['current'] = ($_SESSION['pagenum']-1);
}

echo $_SESSION['current'];
echo "<br/>";
echo ($testArray[$_SESSION['current']]);
$_SESSION['current']++;


}

//BACK
if(isset($_POST["back"]))
{
if($_SESSION['current'] < 0)
{
$_SESSION['current']=0;
}

echo $_SESSION['current'];
echo "<br/>";
echo ($testArray[$_SESSION['current']]);
$_SESSION['current']--;

}

 

 

 

-----------------

 

I've discovered how to fix the glitch. I made sure the $_SESSION['current'] was equal to it's current value after increment/decrement by adding in the line

$_SESSION['current']==$_SESSION['current']

And I moved my greater than list/less than 0 checks below that statement, but above the echo.

 

It works now!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.