Jump to content

variable vanishing?


almightyegg

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.