For some reason X, and Y are being rewritten (only option 1 is showing up but the other stuff is visible) when they're intrtnal to the function (subtracting 1).
<?php
function mapgen($x, $y){
global $con, $cx, $cy, $cz, $m_q, $m_w, $m_e, $m_a, $m_s, $m_d, $m_z, $m_x, $m_c;
$mx=$cx+$x;
$my=$cy+$y;
echo $x.",". $y;
$sql_m= "select * from map WHERE x=$mx AND y=$my AND z=$cz";
$result = mysql_query($sql_m, $con) or die ("can not generate result " . mysql_error());
$row_m = mysql_fetch_assoc($result);
//print_r($row_m);
//echo $mx . "," . $my;
if ($row_m)
{
echo "<img src='images/" . $row_m['img'] . "' alt='terain' height='20' width='20' />";
if ($x='-1' && $y='1')
{$m_q=1;}
else if($x='0' && $y='1')
{$m_w=1;}
else if($x='1' && $y='1')
{$m_e=1;}
else if($x='-1' && $y='0')
{$m_a=1;}
else if($x='0' && $y='0')
{$m_s=1;}
else if($x='1' && $y='0')
{$m_d=1;}
else if($x='-1' && $y='-1')
{$m_z=1;}
else if($x='0' && $y='-1')
{$m_x=1;}
else if($x='1' && $y='-1')
{$m_c=1;}
else
{
echo"error";
}
}
else
{
echo "<img src='images/clear.gif' height='20' width='20' alt='null'>";
}
}
?>