almightyegg Posted March 30, 2008 Share Posted March 30, 2008 I was writing this script and I thought I'd test just this first bit and it isn't working... if(!$move){ $x = 1; $y = 1; echo "Current Position: $x,$y<br />"; echo "<center><a href='pit.php?move=n'>[North]</a><br> <a href='pit.php?move=w'>[West]</a> <a href='pit.php?move=e'>[East]</a><br> <a href='pit.php?move=s'>[south]</a></center>"; }elseif($move == s){ $y = $y+1; echo "Current Position: $x,$y<br />"; echo "<center><a href='pit.php?move=n'>[North]</a><br> <a href='pit.php?move=w'>[West]</a> <a href='pit.php?move=e'>[East]</a><br> <a href='pit.php?move=s'>[south]</a></center>"; }elseif($move == n){ $y = $y-1; echo "Current Position: $x,$y<br />"; echo "<center><a href='pit.php?move=n'>[North]</a><br> <a href='pit.php?move=w'>[West]</a> <a href='pit.php?move=e'>[East]</a><br> <a href='pit.php?move=s'>[south]</a></center>"; }elseif($move == e){ $x = $x+1; echo "Current Position: $x,$y<br />"; echo "<center><a href='pit.php?move=n'>[North]</a><br> <a href='pit.php?move=w'>[West]</a> <a href='pit.php?move=e'>[East]</a><br> <a href='pit.php?move=s'>[south]</a></center>"; }elseif($move == w){ $x = $x-1; echo "Current Position: $x,$y<br />"; echo "<center><a href='pit.php?move=n'>[North]</a><br> <a href='pit.php?move=w'>[West]</a> <a href='pit.php?move=e'>[East]</a><br> <a href='pit.php?move=s'>[south]</a></center>"; } It isn't finding $x and $y properly. If it $move = e or w then it says "Current Position: ,1" and if it is n or s it says "Current Position: 1," and that 1 never changes...never goes up or down...no matter how many pages it goes... Any idea? Link to comment https://forums.phpfreaks.com/topic/98637-variable-vanishing/ Share on other sites More sharing options...
trq Posted March 30, 2008 Share Posted March 30, 2008 Unless you have defined s and the like as constants, these lines.... }elseif($move == s) { ought be.... }elseif($move == 's') { etc etc. Link to comment https://forums.phpfreaks.com/topic/98637-variable-vanishing/#findComment-504780 Share on other sites More sharing options...
almightyegg Posted March 30, 2008 Author Share Posted March 30, 2008 That wasn't the problem but I have found the problem. It's not carrying $x and $y through to each page (hense why it aways stays at -1 or 1). Is there a way I can do this simply? Link to comment https://forums.phpfreaks.com/topic/98637-variable-vanishing/#findComment-504798 Share on other sites More sharing options...
trq Posted March 30, 2008 Share Posted March 30, 2008 Why would it carry them through each page? If you want them to be persistent accross requests, you will need to store them in the $_SESSION array. Link to comment https://forums.phpfreaks.com/topic/98637-variable-vanishing/#findComment-504803 Share on other sites More sharing options...
redarrow Posted March 30, 2008 Share Posted March 30, 2008 use session's ur drive your self crazy man.......... Link to comment https://forums.phpfreaks.com/topic/98637-variable-vanishing/#findComment-504810 Share on other sites More sharing options...
almightyegg Posted March 30, 2008 Author Share Posted March 30, 2008 Right, I've solved that problem thanks for the help guys. Now I have another problem. There are variables like: $p1d1 = blah; $p2d1 = blah; $p3d1 = blah; etc.. $p1d2 = blah; $p2d2 = blah; $p3d2 = blah; etc.. $p1d3 = blah; $p2d3 = blah; $p3d3 = blah; etc.. The first number in each is represented by $x and the second by $y. So when I call the variable I am calling $p$xd$y - of course that doesn't work. What can I do to make it show, in this case, $p1d1??? Link to comment https://forums.phpfreaks.com/topic/98637-variable-vanishing/#findComment-504846 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.