DannyM Posted December 31, 2007 Share Posted December 31, 2007 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 https://forums.phpfreaks.com/topic/83776-solved-nextback-buttons/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.