I am now using arrays and 'while' functions. Thanks for the advice.
However, there is still one problem. My code now looks like this:
<?
session_start();
include 'db.php';
$playerx == $_POST['x'];
$playery == $_POST["y"];
$x = array (
"1" => $playerx-1,
"2" => $playerx,
"3" => $playerx+1,
"4" => $playerx-1,
"5" => $playerx,
"6" => $playerx+1,
"7" => $playerx-1,
"8" => $playerx,
"9" => $playerx+1,
);
$y = array (
"1" => $playery-1,
"2" => $playery-1,
"3" => $playery-1,
"4" => $playery,
"5" => $playery,
"6" => $playery,
"7" => $playery+1,
"8" => $playery+1,
"9" => $playery+1,
);
$result = array();
$i = 1;
while ($i <= 9)
{
$result[$i] = mysql_query("SELECT * FROM map WHERE x = '$x[$i]' AND y = '$y[$i]'");
$i += 1;
}
$i = 1;
while ($i <= 9)
{
$object[$i] = mysql_fetch_object($result[$i]);
$i += 1;
}
$i = 1;
while ($i <= 9)
{
mysql_free_result($result[$i]);
$i += 1;
}
?>
<TABLE BORDER>
<TR>
<? $i = 0;
$u = 1;
while ($i < 3)
{
?>
<TD><form action="map.php" method="post">
<input type=hidden name="x" value="<? $object[$u]->x ; ?>">
<input type=hidden name="y" value="<? $object[$u]->y ; ?>">
<input type="submit" value="<? echo $object[$u]->name ; ?>">
</form>
</TD>
<?
$u += 1;
$i += 1;
}//end of making new cell
$i = 0;
?> </TR><TR>
<?
while ($i < 3)
{
?>
<TD><form action="map.php" method="post">
<input type=hidden name="x" value="<? $object[$u]->x ; ?>">
<input type=hidden name="y" value="<? $object[$u]->y ; ?>">
<input type="submit" value="<? echo $object[$u]->name ; ?>">
</form>
</TD>
<?
$u += 1;
$i += 1;
}//end of making new cell
$i = 0;
?> </TR><TR>
<?
while ($i < 3)
{
?>
<TD><form action="map.php" method="post">
<input type=hidden name="x" value="<? $object[$u]->x ; ?>">
<input type=hidden name="y" value="<? $object[$u]->y ; ?>">
<input type="submit" value="<? echo $object[$u]->name ; ?>">
</form>
</TD>
<?
$u += 1;
$i += 1;
}//end of making new cell
?>
</TR>
</TABLE>
However, when I click on one of the buttons, it does nothing. Can anyone work out what is wrong? The page can be found here: http://staggy11.byethost3.com/map.php