Automatically update php loop with data pulled from database
<p><strong>SQL STRUCTURE</strong></p>

<pre><code>CREATE TABLE IF NOT EXISTS `map` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `x` int(11) NOT NULL,
  `y` int(11) NOT NULL,
  `type` varchar(50) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
</code></pre>

<p><a href="http://localhost/map.php?x=0&amp;y=0" rel="nofollow">http://localhost/map.php?x=0&amp;y=0</a></p>

<p>When I update the x and y via POST or GET, I would like to pull the new data from the database without refreshing the site, how would I manage that? Could someone give me some examples, because I am really stuck here.</p>

<pre><code>&lt;?php


mysql_connect('localhost', 'root', '');
mysql_select_db('hol');

$startX = $_GET['x'];
$startY = $_GET['y'];
$fieldHeight = 6;
$fieldWidth = 6;

$sql = "SELECT id, x, y, type FROM map WHERE x BETWEEN ".$startX." AND ".($startX+$fieldWidth). " AND y BETWEEN ".$startY." AND ".($startY+$fieldHeight);

$result = mysql_query($sql);

$positions = array();

while ($row = mysql_fetch_assoc($result)) {
    $positions[$row['x']][$row['y']] = $row;
}

echo "&lt;table&gt;";
for($y=$startY; $y&lt;$startY+$fieldHeight; $y++) {
    echo "&lt;tr&gt;";
    for($x=$startX; $x&lt;$startX+$fieldWidth; $x++) {
        echo "&lt;td&gt;";
        if(isset($positions[$x][$y])) {
            echo $positions[$x][$y]['type'];
        }
        else {
            echo "(".$x.",".$y.")";
        }
        echo "&lt;/td&gt;";
    }
    echo "&lt;/tr&gt;";
}
echo "&lt;/table&gt;"; 

?&gt;
</code></pre>
